Quadtree / Recursive Quad Split
First appeared 1974 · Raphael Finkel, Jon Bentley — Finkel & Bentley (1974). · timeline ↗
inventor-coined Name · coined by Raphael Finkel, Jon Bentley (1974) — Descriptive name from its inventors: Finkel & Bentley's 1974 paper used "quad trees".
In one line A spatial data structure that recursively divides a rectangle into four quadrants — and, as a generative layout, a way to subdivide a canvas into nested cells driven by detail or randomness.
The code
The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.
quadtree/index.html
const SEED = Math.floor(Math.random()*1e9);
// Flat mid-century palette; each leaf cell picks one.
const PAL = [
[232, 74, 51], [244, 180, 26], [27, 153, 139],
[44, 95, 158], [241, 240, 230], [22, 28, 38],
];
function setup() {
randomSeed(SEED);
const s = Math.min(windowWidth, windowHeight);
createCanvas(s, s);
background(22, 28, 38);
stroke(10);
strokeWeight(Math.max(1, s / 400));
// Recursive quad split: each node either subdivides into four children
// or stops and paints itself. Past a minimum depth the split becomes a
// coin flip, so cell sizes vary across the canvas.
subdivide(0, 0, width, height, 0);
}
function subdivide(x, y, w, h, depth) {
const MAX = 7;
const minLeaf = width / 64;
const stop = depth >= MAX || w <= minLeaf || (depth >= 2 && random() < 0.5);
if (stop) {
const [r, g, b] = PAL[Math.floor(random(PAL.length))];
fill(r, g, b);
rect(x, y, w, h);
return;
}
const hw = w / 2, hh = h / 2;
subdivide(x, y, hw, hh, depth + 1);
subdivide(x + hw, y, hw, hh, depth + 1);
subdivide(x, y + hh, hw, hh, depth + 1);
subdivide(x + hw, y + hh, hw, hh, depth + 1);
}How it works
Start with the whole region as the root node. Recursively: 1. Test a split criterion for the current cell — e.g. it contains more than k points, exceeds a colour-variance threshold over an image, or simply hasn't reached a target depth. 2. If it should split, divide the cell into four equal quadrants and recurse into each; otherwise make it a leaf. The result is a tree whose leaves are fine where detail is high and coarse where it is low. As a structure it accelerates range/nearest queries and collision checks (O(log n)); as a generative composition, colouring each leaf by its average gives the familiar recursive-rectangle (Mondrian/“image quadtree”) look, and random split decisions make irregular nested grids.
Parameters
maxDepth: number — Maximum recursion depth of the subdivision.capacity: number — Points a node holds before it splits into four children.splitThreshold: number — Criterion (e.g. local density or variance) that triggers a split.
Lineage
Frequently combined with
- Perlin / Simplex Noise · 7 works
- HSL / Hue Cycle · 5 works
- Boids / Flocking · 3 works
- Fragment Shader (GLSL) · 3 works
- Flow Field / Vector Field · 3 works
- Bezier / Catmull-Rom Splines · 3 works
- Marching Squares / Contours · 2 works
- Voronoi Diagram · 2 works
- Spring-Mass / Verlet · 2 works
- Particle System · 2 works
- Fractal / Recursive Subdivision · 2 works
- Geometric / Hexagonal Tiling · 1 work
Works using this algorithm (16)
Last updated 2026-07-16