Voronoi Diagram
also: Dirichlet tessellation, Thiessen polygons
First appeared 1908 · Georgy Voronoy — Georgy Voronoy (1908); related Dirichlet tessellation, 1850. · timeline ↗
third-party / eponym Name — An eponym conferred by later mathematicians, not by Voronoy himself — a textbook Stigler's-law case: Dirichlet studied the same tessellation earlier (1850, hence "Dirichlet tessellation"), and the structures recur under many names. The "Voronoi" eponym honours Georgy Voronoy's 1908 treatment. Coiner and date of the name itself not established here (to be confirmed).
In one line A partition of the plane from a set of seed points (sites): every location is assigned to its nearest site, carving the plane into one convex cell per site. Used for cellular patterns and organic tilings.
The code
The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.
voronoi/index.html
const SEED = Math.floor(Math.random()*1e9);
function setup() {
randomSeed(SEED);
const s = Math.min(windowWidth, windowHeight);
createCanvas(s, s);
noStroke();
// Brute-force per-pixel Voronoi for clarity (O(N·W·H)).
// Use a small canvas + scale up to keep it fast.
const W = 240;
const cnv = createGraphics(W, W);
cnv.pixelDensity(1);
const N = 28;
const sites = Array.from({ length: N }, () => ({
x: random(W), y: random(W),
c: [random(40, 230), random(40, 230), random(40, 230)],
}));
cnv.loadPixels();
for (let y = 0; y < W; y++) {
for (let x = 0; x < W; x++) {
let best = 0, bestD = Infinity;
for (let i = 0; i < N; i++) {
const dx = x - sites[i].x;
const dy = y - sites[i].y;
const d = dx*dx + dy*dy;
if (d < bestD) { bestD = d; best = i; }
}
const idx = 4 * (y * W + x);
const c = sites[best].c;
cnv.pixels[idx] = c[0];
cnv.pixels[idx+1] = c[1];
cnv.pixels[idx+2] = c[2];
cnv.pixels[idx+3] = 255;
}
}
cnv.updatePixels();
noSmooth();
image(cnv, 0, 0, width, height);
// Overlay site markers.
fill(0); noStroke();
const r = width / W;
for (const p of sites) circle(p.x * r, p.y * r, width * 0.008);
}How it works
Given a set of sites, the Voronoi cell of a site is the set of all points closer to it than to any other site; cell boundaries lie exactly halfway (perpendicular bisectors) between neighbouring sites, meeting at vertices equidistant from three or more sites. Ways to compute it: 1. Brute force: for each pixel, find the nearest site (simple, slow). 2. Fortune's sweepline algorithm: O(n log n) construction of the exact diagram. 3. As the dual of a Delaunay triangulation: connect circumcentres of adjacent Delaunay triangles. Weighting the distance metric (power/multiplicative) yields additively/ multiplicatively weighted variants.
Parameters
siteCount: number — Number of seed points; each site defines one cell.distanceMetric: string — Distance function assigning points to the nearest site (Euclidean, Manhattan, Chebyshev).relaxation: number — Lloyd-relaxation iterations that even out cell sizes by moving each site to its cell centroid.
Lineage
Frequently combined with
- Fragment Shader (GLSL) · 5 works
- Perlin / Simplex Noise · 5 works
- Flow Field / Vector Field · 4 works
- Bezier / Catmull-Rom Splines · 4 works
- HSL / Hue Cycle · 3 works
- Marching Squares / Contours · 2 works
- Delaunay Triangulation · 2 works
- Quadtree / Recursive Quad Split · 2 works
- Raymarching with SDFs · 2 works
- Plotter-style Hatching · 2 works
- Particle System · 2 works
- Boids / Flocking · 1 work
Works using this algorithm (9)
Last updated 2026-07-16