19. Reaction-Diffusion
Spots, stripes, and labyrinths from two interacting chemicals
In 1952, Alan Turing published a paper titled The Chemical Basis of Morphogenesis. In it, he proposed that the patterns on animal skins — spots on a leopard, stripes on a zebra, the labyrinthine folds of a brain — could arise from two chemicals reacting and diffusing at different rates. No blueprint, no genetic instruction for "put a spot here." Just two substances, interacting locally, producing global pattern.
The Gray-Scott model is the most popular reaction-diffusion system for generative art. It's simple to implement, runs on a 2D grid, and produces an astonishing variety of patterns depending on just two parameters.
Two Chemicals, Two Rules
The system tracks two substances on a grid:
- U (the substrate) — starts everywhere at concentration 1.0
- V (the catalyst) — starts at 0.0 except for a small seed region
At each time step, two things happen simultaneously:
- Reaction — V consumes U to produce more V. The reaction rate depends on how much U and V are present at each cell.
- Diffusion — both U and V spread to neighboring cells, but at different rates. U diffuses faster than V.
The key insight: because U diffuses faster, it effectively runs away from V. V can only grow where U is present, but U keeps escaping. This chase creates the patterns.
The Gray-Scott Equations
Breaking this down term by term:
| Term | Meaning |
|---|---|
| Du ∇²U | U diffuses (spreads to neighbors) |
| Dv ∇²V | V diffuses (more slowly) |
| -UV² | U is consumed by the reaction (U + 2V → 3V) |
| +UV² | V is produced by the reaction |
| f(1 - U) | U is replenished at feed rate f |
| -(f + k)V | V decays at kill rate k (plus is washed away at rate f) |
The two parameters that control everything:
- f (feed rate) — how fast U is replenished. High f means plenty of substrate; low f means V starves.
- k (kill rate) — how fast V decays. High k means V dies quickly; low k means it persists.
The parameter space
Different (f, k) pairs produce completely different patterns: spots, stripes, waves, spirals, mitosis-like splitting, or uniform steady states. The boundary between these regimes is where the most complex patterns emerge — the system balances on the edge between growth and decay.
Implementing It on a Grid
The simulation runs on a 2D grid where each cell stores a U and V concentration. At each time step:
- Compute the Laplacian for each cell — how much its value differs from its neighbors
- Apply the reaction-diffusion equations to update U and V
The discrete Laplacian
The Laplacian ∇² measures how much a cell differs from its neighbors. On a grid, we approximate it with a convolution kernel:
| 0.05 0.2 0.05 |
∇²A = | 0.2 -1.0 0.2 | convolved with A
| 0.05 0.2 0.05 |
This weighted average of the 8 neighbors minus the center value gives a good approximation of continuous diffusion.
The update loop
for each cell (i, j):
lapU = laplacian(U, i, j)
lapV = laplacian(V, i, j)
uvv = U[i][j] * V[i][j] * V[i][j]
U_next[i][j] = U[i][j] + (Du * lapU - uvv + f * (1 - U[i][j])) * dt
V_next[i][j] = V[i][j] + (Dv * lapV + uvv - (f + k) * V[i][j]) * dt
swap U with U_next
swap V with V_next
Typical constants: Du = 0.21, Dv = 0.105 (V diffuses at half the rate of U), dt = 1.0.
The Pattern Zoo
The Gray-Scott parameter space contains a remarkable variety of patterns:
Spots (f ≈ 0.035, k ≈ 0.060)
Isolated dots of V that maintain their size. They can split (mitosis) to fill space, creating a pattern reminiscent of a leopard's spots.
Stripes (f ≈ 0.04, k ≈ 0.06)
V forms elongated, winding ridges. The stripes have a characteristic width determined by the diffusion ratio and maintain even spacing through mutual repulsion — much like a zebra's pattern.
Spirals (f ≈ 0.014, k ≈ 0.045)
Rotating spiral waves that resemble the Belousov-Zhabotinsky chemical reaction. These are among the most dynamic patterns — they spin continuously and never reach a steady state.
Coral / maze (f ≈ 0.06, k ≈ 0.062)
Dense, labyrinthine structures that fill most of the space. The boundary between U and V regions forms an intricate, brain-like folding pattern.
Mitosis (f ≈ 0.028, k ≈ 0.060)
Spots that grow, elongate, and split into two — a convincing simulation of cell division. The daughter spots grow and split again, filling the grid through repeated doubling.
Try It: Reaction-Diffusion Simulator
Choose a pattern preset or set custom feed and kill rates. Click the canvas to seed V in new locations. The simulation runs continuously.
Reaction-Diffusion Simulator
Why Different Rates Matter
The entire mechanism depends on U diffusing faster than V. If both diffused at the same rate, the reaction would either take over everywhere or die out everywhere — no pattern.
The faster diffusion of U creates a phenomenon called local activation, long-range inhibition:
- Locally, V grows by consuming U (activation)
- At a distance, U has already diffused away, starving V of fuel (inhibition)
This means V can sustain itself at its current location but can't easily expand. The result is stable structures with a characteristic size — spots with a preferred radius, stripes with a preferred width. This size is set by the ratio of diffusion rates, not by any explicit length parameter.
Turing Patterns in Nature
Reaction-diffusion isn't just a mathematical curiosity. Real biological patterns follow the same mechanism:
- Zebrafish stripes — melanophore and xanthophore pigment cells interact through short-range activation and long-range inhibition, exactly as Turing predicted
- Seashell patterns — the growth edge of a shell is a 1D reaction-diffusion system; the shell's surface records its history, creating 2D patterns
- Digit formation — the spacing of fingers and toes in embryonic development is governed by a Turing-type mechanism involving BMP and WNT signaling molecules
- Vegetation patterns — fairy circles in Namibian grasslands and banded vegetation in arid regions follow reaction-diffusion dynamics where water and biomass play the roles of U and V
Turing's 1952 paper was decades ahead of its time. The biological evidence has only caught up in the last twenty years.
Beyond Gray-Scott
The Gray-Scott model is just one reaction-diffusion system. Others include:
- FitzHugh-Nagumo — originally a model of nerve impulse propagation, produces traveling waves and spiral patterns
- Brusselator — a theoretical model that generates oscillating chemical concentrations and spatial patterns
- Schnakenberg — a minimal two-component system with well-understood bifurcation behavior
- Multi-species systems — three or more interacting chemicals can produce patterns impossible with two, including hexagonal lattices and quasicrystal-like tilings
The common thread: simple local rules, applied uniformly across a grid, producing complex global structure. No central controller, no template, no blueprint — just chemistry and diffusion.
What's Next
Reaction-diffusion produces pattern from continuous concentrations on a grid. Next we'll explore cellular automata — systems where each cell is simply alive or dead, yet Conway's Game of Life and Wolfram's elementary rules generate astonishing complexity from the simplest possible update rules.