@@ -5,8 +5,8 @@ uid: HQImLPf2Tmel6kw8hCis3vcJnLo2
55datePublished : 2026-03-25
66published : false
77description : Learn to build a browser-based pixel art editor using HTML Canvas, 2D arrays, and vanilla JavaScript. Draw, erase, flood fill, and export your pixel art as PNG.
8- header : TBD
9- bannerImage : TBD
8+ header : https://firebasestorage.googleapis.com/v0/b/codedex-io.appspot.com/o/projects%2Fbuild-a-pixel-art-creator-with-html-css-and-javascript%2Fbanner.gif?alt=media&token=024ec787-541b-456f-b82b-76eda7ed7657
9+ bannerImage : https://firebasestorage.googleapis.com/v0/b/codedex-io.appspot.com/o/projects%2Fbuild-a-pixel-art-creator-with-html-css-and-javascript%2Fbanner.gif?alt=media&token=024ec787-541b-456f-b82b-76eda7ed7657
1010readTime : 75
1111prerequisites : HTML, CSS, JavaScript fundamentals
1212versions : None
@@ -61,7 +61,7 @@ A pixel art canvas is just a grid of colored squares. In code, we represent this
6161 [" #ffffff" , " #ff0000" , " #ffffff" ],
6262 [" #ff0000" , " #ff0000" , " #ff0000" ],
6363 [" #ffffff" , " #ff0000" , " #ffffff" ],
64- ]
64+ ];
6565```
6666
6767Each value is a hex color string. The position in the array corresponds to a cell on the grid: ` grid[row][col] ` gives us the color at that position.
@@ -134,7 +134,7 @@ Find the `init()` function in the starter code and add the following code:
134134``` javascript
135135function init () {
136136 grid = Array .from ({ length: gridSize }, () =>
137- Array (gridSize).fill (" #ffffff" )
137+ Array (gridSize).fill (" #ffffff" ),
138138 );
139139
140140 cellSize = Math .floor (480 / gridSize);
@@ -371,7 +371,9 @@ function buildPalette() {
371371 swatch .addEventListener (" click" , () => {
372372 currentColor = color;
373373 document .getElementById (" custom-color" ).value = color;
374- document .querySelectorAll (" .color-swatch" ).forEach ((s ) => s .classList .remove (" active" ));
374+ document
375+ .querySelectorAll (" .color-swatch" )
376+ .forEach ((s ) => s .classList .remove (" active" ));
375377 swatch .classList .add (" active" );
376378 });
377379 palette .appendChild (swatch);
@@ -392,7 +394,9 @@ Find the TODO marked `Step 4-b` and add the custom color picker handler:
392394``` javascript
393395document .getElementById (" custom-color" ).addEventListener (" input" , (e ) => {
394396 currentColor = e .target .value ;
395- document .querySelectorAll (" .color-swatch" ).forEach ((s ) => s .classList .remove (" active" ));
397+ document
398+ .querySelectorAll (" .color-swatch" )
399+ .forEach ((s ) => s .classList .remove (" active" ));
396400});
397401```
398402
@@ -406,7 +410,9 @@ Find the TODO marked `Step 4-c` and wire up the tool buttons:
406410document .querySelectorAll (" .tool-btn" ).forEach ((btn ) => {
407411 btn .addEventListener (" click" , () => {
408412 currentTool = btn .dataset .tool ;
409- document .querySelectorAll (" .tool-btn" ).forEach ((b ) => b .classList .remove (" active" ));
413+ document
414+ .querySelectorAll (" .tool-btn" )
415+ .forEach ((b ) => b .classList .remove (" active" ));
410416 btn .classList .add (" active" );
411417 });
412418});
@@ -427,7 +433,7 @@ Find the TODO marked `Step 5` and wire up the grid size dropdown:
427433``` javascript
428434document .getElementById (" grid-size" ).addEventListener (" change" , (e ) => {
429435 const confirmed = confirm (
430- " Changing grid size will clear your canvas. Continue?"
436+ " Changing grid size will clear your canvas. Continue?" ,
431437 );
432438 if (confirmed) {
433439 gridSize = parseInt (e .target .value );
@@ -470,7 +476,7 @@ document.getElementById("export-btn").addEventListener("click", () => {
470476 col * exportCellSize,
471477 row * exportCellSize,
472478 exportCellSize,
473- exportCellSize
479+ exportCellSize,
474480 );
475481 }
476482 }
0 commit comments