Draw My Canvas / studio

Voronoi Drift

Every point on the plate belongs to whichever seed is nearest. The lines are the places that cannot decide — and the seeds will not hold still.

Plate 15voronoi-lloyd

Waiting for the animation above to load…

What lands in the file, and what the width does

One click writes whatever the animation is drawing at that moment to a PNG, with the drawmycanvas.com mark drawn into the picture rather than laid over it. Leave the width box empty and you get the stage exactly as your browser rasterised it — your window’s width times its device pixel ratio, which is about 1,600 px across from a 1280‑px window on a HiDPI laptop and about 353 px from a 390‑px phone.

Type a width instead, or take a preset, and the frame is redrawn into a canvas that wide: the height follows the stage’s own shape and the mark scales with it. The stage is 16:9 on a wide window and 4:3 below 560 px, so a width of 1200 saves 1200×675 on a laptop and 1200×900 on a phone. 1200 px is the width Open Graph and X link cards are cut from — the canonical card is 1200×630, and a card crops the extra height rather than letterboxing it.

Honest limits. Asking for more pixels than the stage was drawn at resamples pixels that were never drawn: a 1920‑px file exported from a 353‑px phone stage is bigger, not sharper. A very large width is a real memory allocation and a browser is allowed to refuse it; when that happens the line above says so plainly and nothing else on the page changes. PNG only — no JPEG, no WebP, no animated export. And nothing is uploaded: the picture is assembled in your own browser, so no frame of this plate ever reaches us.

Live on an HTML canvas · vanilla JavaScript · no dependencies Open fullscreen

About this piece

Scatter a few dozen seeds. Every other point on the plate belongs to whichever seed is nearest to it, and the region a single seed owns is its Voronoi cell. The lines you can see are the ties — the points that cannot decide between two seeds — and each one is exactly the perpendicular bisector of a pair of neighbouring seeds. Georgy Voronoy formalised the construction in 1908, but John Snow had already drawn one by hand in 1854, mapping which London houses were nearer the Broad Street pump than any other, to argue that cholera came from water.

It is also everywhere in nature for a dull and honest reason: whenever things grow outward from scattered centres at the same rate and stop where they meet, the boundaries you get are a Voronoi diagram. Dried mud, giraffe markings, grain boundaries in cooled metal, the cracks in glaze.

Built by clipping, not by sampling

Each cell here starts as the whole frame rectangle and is then clipped, one seed at a time, against the half-plane “closer to me than to that one” — the standard Sutherland–Hodgman polygon clip, run once per other seed. That is O(n²) and would be the wrong algorithm at ten thousand seeds; Fortune’s sweepline gets you O(n log n) and exists for exactly that case. At the 24–40 seeds used here it is a few hundred half-plane clips per frame, roughly a third of a millisecond, and it buys real polygon geometry.

The cheap alternative is to decide an owner per pixel on a coarse grid and mark the disagreements. It is faster, and it is what this piece deliberately does not do: sampled walls come out staircased, and on the light theme a staircased hairline reads as a compression artefact rather than as a drawn line. Clipped polygons stay a clean hairline at any window size.

What makes it move

Two forces that never agree. The first is Lloyd relaxation: move each seed to the centroid of its own cell, then rebuild the diagram, and repeat. Its fixed points are centroidal Voronoi tessellations, and they are strikingly even — run it to convergence on random seeds and the cells go nearly hexagonal, which is why the same loop is used for stippling, for mesh generation and for k-means clustering. This piece takes only 5% of that step per frame, so the tessellation is permanently mid-relaxation rather than settled.

The second is a slow two-frequency drift on every seed, which keeps moving the target Lloyd is chasing. Neither wins. That is the whole composition: walls that are always tidying themselves and never finish. Click the canvas to throw the seeds away and start from a fresh scatter — the first second or two after a click is the relaxation doing its most visible work.

What to look for

The clip rectangle is deliberately larger than the window, so the outer boundary of the diagram falls off-screen and every line you can see is a genuine wall between two cells rather than the edge of a box. Watch a wall that separates two cells drifting apart: it does not slide, it pivots, because a bisector is pinned to the midpoint of the two seeds and turns with them. And watch cells with few neighbours grow — a cell with three walls is nearly always one that is about to be squeezed out.

Honest limits: this is the ordinary Euclidean diagram with all seeds weighted equally. Weighted (power) diagrams size each cell to its seed and are far more useful for real work, but under drift they let cells vanish outright, which reads as a glitch rather than as motion. Walls only, no fills — thirty distinct cell colours is not a palette this site has, and flooding a near-black plate with light blocks is how a palette stops being legible. Reduced-motion visitors get the relaxation run 90 steps and then held as a single still frame.

Curious how the loop and canvas fit together? Read how it works →

More from the gallery

All 22 animations in the gallery →