Reaction-diffusion

Two chemicals, a GPU, and Turing’s 1952 hunch

Two chemicals diffuse across a surface and react where they meet. That’s the whole setup. Get the rates right and it stops being boring: the even mix goes unstable and sorts itself into spots, stripes, mazes, and blobs that split like dividing cells. Alan Turing wrote the maths down in 1952, as an answer to how a featureless ball of cells decides where to put a leopard’s spots. It’s the smooth cousin of the Game of Life on the other page here: same idea, local rules run in parallel until structure emerges, but continuous instead of square.

The version below is Gray-Scott. Two species, a feed rate that tops up the first, a kill rate that drains the second, and a reaction that turns one into the other. Move those two numbers and the same equations hand you coral, fingerprints, or self-replicating dots. Pick a preset and watch, or click on the canvas to drop in some chemical and start a pattern yourself.

It all runs on the GPU. The state, two concentrations per cell, lives in a floating-point texture. A single fragment shader reads each cell and its four neighbours, applies a 5-point Laplacian for the diffusion term, does the Gray-Scott reaction, and writes the next state. A shader can’t read and write the same texture at once, so it ping-pongs between two of them: read A, write B, swap, repeat, a few dozen times per frame before anything reaches the screen.

Click or drag on the canvas to add chemical and seed new growth.

The two knobs

Everything on screen is steered by two numbers: the feed rate F and the kill rate k. Most of the (F, k) plane is dead, the pattern either floods solid or starves to nothing. The interesting behaviour lives on a thin band between those fates, and small steps along it flip you between mazes, drifting spots, and mitosis. The presets drop you onto known-good points, and the F and k sliders let you wander off them and find your own; the links below map the rest.

Further reading

← back to haigh.bio

Turing would’ve loved a fast GPU.