This is the sample post that ships with the site. It explains the animation on the home page, and along the way it uses every building block a post can use: math, code, a figure, sidenotes, citations, callouts, an interactive widget, and a BibTeX block. Replace it with your own.
The animation shows one small image, about 160 by 90 pixels, redrawn with a palette of 2 colors, then 4, 8, 16, 64 and 256. With 2 colors you see blobs. By 256 you see the whole scene. The code that does this is about a hundred lines, in src/lib/quantize.ts.
Fewer colors
Quantizing an image means choosing a small palette of colors and replacing every pixel with its nearest palette entry:
A pixel of the original takes 24 bits. A pixel of the quantized image is an index into the palette, which takes bits.
| Colors | 2 | 4 | 8 | 16 | 64 | 256 |
|---|---|---|---|---|---|---|
| Bits per pixel | 1 | 2 | 3 | 4 | 6 | 8 |
The same operation, nearest entry in a codebook, is how VQ-VAE turns continuous latents into discrete tokens [1]. There the codebook is learned; here it is computed from the image.
Choosing the palette
The palette comes from median cut [2]. Put every pixel in one box in RGB space. Find the box whose pixels are most spread out along some channel, sort its pixels along that channel, and split it at the median. Repeat until there are boxes. Each box contributes one palette color: the mean of its pixels.
Diffusing the error
Nearest-color rounding alone gives flat bands. Floyd–Steinberg dithering [3] fixes that by keeping track of the rounding error at each pixel and adding it to the neighbors that have not been visited yet, in these proportions:
The star is the current pixel. The weights sum to one, so away from the image edges no error is lost: a region’s average color survives even when no single pixel has that color.
In code, the diffusion step is a few lines per color channel:
for (let c = 0; c < 3; c++) {
const err = work[i + c] - nearest[c];
if (x + 1 < w) work[i + 4 + c] += (err * 7) / 16;
if (y + 1 < h) {
const below = i + w * 4 + c;
if (x > 0) work[below - 4] += (err * 3) / 16;
work[below] += (err * 5) / 16;
if (x + 1 < w) work[below + 4] += err / 16;
}
}
Try it

What failed
A palette built from the extremes of the image instead of the means should dither over more of it. That is untested, and the palette is left as is, because the blobs resolving into detail are the point of the animation.
Cite this note
@misc{aporia2026resolving,
author = {Kavya B S},
title = {Resolving an image, one color at a time},
year = {2026},
month = nov,
howpublished = {Aporia Labs},
url = {https://aporia-labs.vercel.app/posts/resolving-an-image/}
}References
- van den Oord, A., Vinyals, O., & Kavukcuoglu, K. (2017). Neural discrete representation learning. Advances in Neural Information Processing Systems 30. Link
- Heckbert, P. (1982). Color image quantization for frame buffer display. ACM SIGGRAPH Computer Graphics, 16(3), 297–307. Link
- Floyd, R. W., & Steinberg, L. (1976). An adaptive algorithm for spatial greyscale. Proceedings of the Society for Information Display, 17(2), 75–77.
