Substrate

also: crack propagation, perpendicular line growth

First appeared 2003 · Jared Tarbell — Popularized by Jared Tarbell's "Substrate" (2003), an open-source Processing sketch published at complexification.net. · timeline ↗

inventor-coined Name · coined by Jared Tarbell (2003) — The artist named his own 2003 work "Substrate"; the technique took the artwork's name.

In one line An agent-based line-growth system in which lines advance across a plane and spawn new lines perpendicular to themselves; each line travels until it collides with another and stops, producing dense crystalline, crack-like or city-map-like networks.

Substrate · 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.

substrate/index.html
// A re-implementation after Jared Tarbell's Substrate crack-propagation (2003) —
// not the original Processing work. Lines ("cracks") advance until they hit
// another and stop; a stopped crack seeds a new one perpendicular to an existing
// line. Constants are a plausible reconstruction.
const SEED = Math.floor(Math.random() * 1e9);
const EMPTY = -1;
let W, H, grid, cracks, made, MAX;

function seedCrack() {
  for (let t = 0; t < 2000; t++) {
    const px = Math.floor(Math.random() * W), py = Math.floor(Math.random() * H);
    if (grid[py * W + px] !== EMPTY) {
      let a = grid[py * W + px] + (Math.random() < 0.5 ? 90 : -90) + (Math.random() - 0.5) * 4;
      cracks.push({ x: px + 0.61, y: py + 0.61, a: (a * Math.PI) / 180 });
      return;
    }
  }
  cracks.push({ x: Math.random() * W, y: Math.random() * H, a: Math.random() * Math.PI * 2 });
}

function setup() {
  randomSeed(SEED);
  const s = Math.min(windowWidth, windowHeight);
  createCanvas(s, s);
  background('#f4f1ea');
  W = width; H = height;
  grid = new Int16Array(W * H).fill(EMPTY);
  MAX = Math.floor((W + H) * 0.9);
  cracks = []; made = 0;
  for (let i = 0; i < 3; i++) {                       // initial seeds
    const x = Math.floor(Math.random() * W), y = Math.floor(Math.random() * H);
    grid[y * W + x] = Math.floor(Math.random() * 360);
    cracks.push({ x, y, a: (grid[y * W + x] * Math.PI) / 180 });
    made++;
  }
  stroke(20, 55);
  strokeWeight(1);
}

function draw() {
  for (let step = 0; step < 180; step++) {
    for (let i = cracks.length - 1; i >= 0; i--) {
      const c = cracks[i];
      const nx = c.x + Math.cos(c.a), ny = c.y + Math.sin(c.a);
      const gx = Math.floor(nx), gy = Math.floor(ny);
      if (gx < 0 || gy < 0 || gx >= W || gy >= H) {
        cracks.splice(i, 1); if (made < MAX) { seedCrack(); made++; } continue;
      }
      const gi = gy * W + gx;
      if (grid[gi] === EMPTY) {
        grid[gi] = ((Math.round((c.a * 180) / Math.PI)) % 360 + 360) % 360;
        point(nx, ny);
        c.x = nx; c.y = ny;
      } else {                                          // collision → stop, spawn perpendicular
        cracks.splice(i, 1); if (made < MAX) { seedCrack(); made++; }
      }
    }
  }
  if (cracks.length === 0) noLoop();
}

Open the demo source ↗

How it works

Maintain a set of moving "cracks" (lines), each with a position and heading. Iterate: 1. Advance: move each crack one step along its heading, drawing as it goes. 2. Collision: if a crack reaches a pixel already occupied by another crack (or the canvas edge), stop it. 3. Spawn: stopped cracks (and seeds) start new cracks at points along existing lines, headed perpendicular (±90°, with a small random jitter) to the line they branch from. The perpendicular-branching rule is what yields the characteristic rectilinear, fractured partitioning of the plane.

Parameters

Lineage

Precedents
Jared Tarbell
Related
Diffusion-Limited Aggregation, Physarum (Slime-Mould Agents), Reaction-Diffusion

Works using this algorithm (1)

Substrate
jared-tarbell

Last updated 2026-07-16