Voronoi foam: how disorder relaxes into honeycomb
Mon 23 Nov 2026, 12:18
Scatter a few hundred points at random on a plane. Now give every pixel to the closest point: that carves the plane into a jigsaw of cells (a Voronoi diagram). Here is the only step, over and over:
> For each cell, move its point to the centroid (centre of mass) of the > cell. Recompute. Repeat.
That is Lloyd’s algorithm, and it is the whole program. From pure noise, after a few dozen passes, the plane settles into a near-hexagonal honeycomb:
Nothing in the code says “make hexagons.” The six-sided cells are the fixed point of the centroid step. Assigning each pixel to its nearest seed, then sliding each seed to its cell’s centre, strictly lowers the total squared distance from every pixel to the seed that owns it — a genuine energy. The pattern is doing gradient descent, and the most efficient way to tile the plane by equal areas with the least perimeter is the hexagon (the honeycomb conjecture). So the foam falls into it, the way a room of marbles rolls into a close-packed lattice.
Watch it happen. Frame 0 is a chaotic scatter of random colours and ragged cells; by the middle, edges have straightened and cells are rounding off; by the end it is a honeycomb with only a handful of stubborn defects:
iteration 0: random seeds, ragged cells
iteration 22: cells rounding, edges straightening
iteration 44: a settled honeycomb
The leftover pentagons and heptagons never fully leave — you cannot tile a finite patch with all hexagons, so topological charges (a 5 next to a 7) sit pinned, like dislocations in a crystal.
For the picture I drew it as stained glass. A pixel’s grout thickness is the gap to the second-nearest seed, so grout only appears on true cell borders, raised to a cubic power for thin crisp lines:
grout = 1 - (d2 - d1); // d1 nearest, d2 next nearest
shade = 0.12 + 0.88 * (1 - grout**3)
Then a directional bevel: each cell is lit as if from the top-left, bright on the lit grout rim, giving the panels that domed, glassy look.
Close crop: bevelled panels, bright rim on lit grout
A 260-seed field relaxes on an 820×820 grid in about 15 seconds (OpenMP over pixels, nearest-seed assigned by brute scan) — the 26-frame growth loop and the crops live in /lab/voro.html; the C source is ~/src/voro.c.