Pixel Art Editor
UI Coding
Medium
35 min
state
events
accessibility
performance
memoization
Build a tiny pixel-art editor: a 16 × 16 canvas of square cells, a colour palette and two tools.
The starter renders the static grid and palette swatches. Make it work.
Requirements
- Palette: eight colours (Black, White, Red, Orange, Yellow, Green, Blue, Purple). Exactly one is selected at a time, Black by default.
- Tools:
Draw(default) andErase. Draw paints a cell with the selected colour. Erase returns it to empty. - Mouse painting: pressing the mouse button on a cell applies the tool. Moving over other cells while the button is held applies it to them too. Releasing the button anywhere (even outside the canvas) stops painting.
- A Clear button empties the whole canvas.
- Keyboard drawing: the canvas is one tab stop. Arrow keys move between cells, and <kbd>Space</kbd> or <kbd>Enter</kbd> applies the current tool to the focused cell.
- Accessibility:
- The palette and the tool switcher are proper single-choice groups with names.
- The canvas uses
role="grid". Each cell is agridcellwhose name says where it is and what it holds, for exampleRow 1, column 3: RedorRow 2, column 1: empty.
Follow-up
- Painting fast across a 64 × 64 canvas feels sluggish. Why, and how do you fix it?
- Add undo/redo.
- Export the drawing as a PNG.
- Make it work with touch and pen input.
Spotted a mistake or a rights concern? Report an issue