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.

Quadtree / Recursive Quad Split · Open in new tab ↗ · Motion begins only when you press Run.

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);
}

Open the demo source ↗

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

Lineage

Related
Poisson Disk Sampling

Frequently combined with

Works using this algorithm (16)

Aerial View
dalenz
Ancient Courses of Fictional Rivers
robert-hodgin
Automatism
yazid
Cytographia
golan-levin
Democracity
generative-artworks
Fermented Fruit
cyberia
flora, fauna, false gods & floods
ryan-green
ilumz
wolffia-inc-motus-art
Interferences
juan-pedro-vallejo
Lacunae
james-dalessandro
Machine Comics
roni-block
pseudomods
erin-bee
Radiance
julien-gachadoat
SKEUOMORPHS
itsgalo
Twist
rafael-rozendaal
Window
jan-robert-leegte

Last updated 2026-07-16