Skip to content
Adrien Hubert

Reaction-diffusion, by Gray and Scott.

Two abstract chemicals share a square. U is everywhere; V is sprinkled in a few spots. They diffuse at different speeds, and where they meet, two molecules of V eat one of U and make a third V. A slow feed replenishes U, a slow drain removes V. Four numbers, run in a tight loop, are enough to grow spots, stripes, coral, and dividing cells.

Mitosis · F=0.0367 · k=0.0649

Click and drag on the canvas to brush V into the field. The grid wraps, so patterns leaving one edge come in from the other.

The equations

Two scalar fields, U and V, sit on a grid. At every step, each cell looks at its eight neighbours, takes a weighted average to estimate how much U and V are diffusing in or out, then applies the chemistry: U + 2V → 3V. The full update for one cell is

U' = U + (Du · ∇²U  −  U·V²  +  F · (1 − U)) · Δt
V' = V + (Dv · ∇²V  +  U·V²  −  (F + k) · V) · Δt

Du and Dv are diffusion rates, fixed here at 1.0 and 0.5. F is how fast U is fed in from outside; k is how fast V is killed off. Δt is the time step, set to 1. The Laplacian ∇² uses a 3×3 stencil with the centre cell at −1, the four edge neighbours at 0.2, and the four corner neighbours at 0.05.

Why patterns appear

U diffuses twice as fast as V. That difference is the whole trick. Where a small clump of V forms, it locally depletes U faster than U can flow in to replace it, so V stops growing at the centre. At the same edge, U is still arriving from outside, which feeds a new ring of V just beyond the original spot. Repeat that logic over a few thousand steps and you get the patterns below: the spot splits, the ring breaks into worms, the worms close into mazes.

Alan Turing first proposed this kind of process in 1952 as a model for how an animal embryo could turn from a uniform ball of cells into one with stripes, spots, or limbs. Gray and Scott's particular choice of chemistry came in 1984, and the parameter map most people use to navigate it was drawn by John Pearson in 1993.

The presets

The six presets are landmarks on that parameter map. Spots (F=0.025, k=0.060) are the simplest: V settles into still roughly-equal dots. Stripes (F=0.022, k=0.051) lets V grow long enough to elongate rather than pinch off. Coral (F=0.0545, k=0.062) grows tip by tip and never quite fills. Mitosis (F=0.0367, k=0.0649) splits one spot into two, then four, then more. Bacteria (F=0.014, k=0.045) crowds the field. Solitons (F=0.030, k=0.062) holds steady self-replicating drops that drift through each other.

Implementation

The grid is 200×200, held in two pairs of Float32Array buffers that ping-pong between read and write. Each animation frame advances the simulation by twenty substeps, then copies the V field into an ImageData as a white-to-amber gradient and blits it onto the canvas. The boundaries wrap, so the field is a torus rather than a square. On a recent laptop this stays comfortably above sixty frames per second; on a phone it slows but still runs.

Sources

  • Turing, A. M., "The Chemical Basis of Morphogenesis", Philosophical Transactions of the Royal Society B, 1952.
  • Gray, P. and Scott, S. K., "Autocatalytic Reactions in the Isothermal, Continuous Stirred Tank Reactor", Chemical Engineering Science, 1984.
  • Pearson, J. E., "Complex Patterns in a Simple System", Science vol. 261, 1993, pp. 189-192. The five labelled parameter regions in this paper are where most of the presets above come from.
  • Sims, K., "Reaction-Diffusion Tutorial" (karlsims.com/rd.html), for the white-paper-friendly numerical scheme used here.