Feature Library

Pixel-art layer

2.31 CPU ms
A still of the Pixel-art layer demo
Still
The live demo starts when it’s in view.Click for sparkles · drag the line to compare with the vector drawing

Draw with ordinary Canvas 2D calls (circles, gradients, paths) at a low resolution, and get true pixel art.

What it costs a frame

2.31 ms
GPU
not used
CPU, median
2.31 ms
CPU, 95th pct
4.91 ms
Draw calls
0
Weight
Heavy

Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 2.25–2.35 ms). What ran: Measured with the world stepping at 12 frames a second and a burst of 28 particles every 0.7 s (they move every frame), so the frames hold the drawing of the three planes at art resolution, the composite (ordered dither, palette snap and outline over about 130,000 art pixels a plane at 1920×1080 with 4 px art pixels) and the vector half of the comparison. At rest nothing is drawn. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring toolnot timed2.314.91
apple · Apple A19 Proin a browser tab · 16 November 2026not timed3.628.08
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026not timed1.793.67

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
Canvas 2DA 2D canvas: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages

What it’s for

  1. Retro and playful themes
  2. Game menus and HUDs in pixel art
  3. Pixel-art backgrounds behind a DOM interface
  4. Turning vector drawings into pixel art
  5. Limited-palette effects (two inks, four greens)
  6. Pixel banners and titles

Pitfalls, in brief

  1. Pixel art needs every art pixel to be a whole number of device pixels, or columns come out one pixel wider than their neighbours.
  2. Put the layer at a whole device pixel.
  3. Each render reads the planes back with getImageData: keep the art resolution low (an art pixel of 3 px or more), render only when something changed, and pass render(from) the first plane that changed, so a still background is reused.
  4. Planes are 2D contexts made with willReadFrequently, so they live on the CPU: draw on them with the usual calls, but do not draw a large image onto them every frame.
  5. Resizing the host clears the planes (their canvases change size): redraw them in onResize, or the next render shows an empty picture.
3 more in brief
  1. Snapping to a palette uses a 15-bit table (5 bits a channel): two palette colours closer than about 8 levels in every channel can map to the same entry.
  2. Text in the picture is decoration.
  3. The demo moves the world in steps (12 a second) like sprite animation, and stops under reduced motion; particles still move every frame while they live.
8 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Bryce Bayer (1973): the ordered-dither threshold matrices (4×4 and 8×8)

Thiadmer Riemersma, “Colour metric” (CompuPhase): the red-mean weighted colour distance used to find the nearest palette colour

pixel artcanvas 2dnearest neighbourimage-rendering pixelatedordered ditherbayerpalettequantizeoutlinebitmap fontretrodevice pixel rationo dependencies

Near it in the frame