Skip to main content

Playground · research instrument

Reaction–Diffusion Pattern Lab

Two chemicals, one reaction, and a grid that wraps at its edges. Paint V with your pointer and watch it branch into coral, split into dividing spots or settle into fingerprint ridges, then drag across the parameter map to change the chemistry while it runs.

Independent research instrument — not claimed as MakerPortal shipped product code. Methods, equations, assumptions, and limitations are disclosed so you can inspect what the page does and does not establish.

Gray–Scott, live

Warming up from the shipped seed…

Chemical V on a 256 × 256 torusDrag to paint

Keyboard: focus the field, move the brush with the arrow keys, press Space to paint.

Pearson’s (k, F) mapDrag to change chemistry

Branching labyrinths that keep growing outward from every seed.

Steps run
—
Coverage (V > 0.1)
—
Mean V
—
Distance to curve
—

Anatomy of the instrument

What each canvas, control and readout above is doing, and the reason it is built that way.

The two canvases

  1. 01

    The field (left). One pixel per grid cell, 256 × 256 of them, scaled up by the browser. Colour is the concentration of V only: the page ground where V is absent, the accent colour at middling V, full-contrast ink where V is densest. U is not drawn; it is roughly the complement of V, so drawing both would add nothing. The grid is a torus: a pattern that leaves the right edge comes back on the left.

  2. 02

    The parameter map (right). Kill rate kk runs across from 0.040 to 0.072, feed rate FF runs up from 0.004 to 0.080. The curve is the saddle-node line k=F/2−Fk = \sqrt{F}/2 - F; on the shaded side no uniform mixed state exists, so only concentrated patches of V can hold on. Each dot is a preset. The ring is where the simulation is right now; drag it and the chemistry changes on the next step without touching the field.

  3. 03

    The brush. A disc that adds V and removes the same amount of U, falling off toward its rim and never pushing either outside [0, 1]. It is the same function that places the starting seed. On a keyboard, focus the field and use the arrow keys to move the brush ring and Space to paint.

Controls, readouts and the loop

  1. 01

    Presets. Each sets FF and kk and reseeds the field, so what you see grows from the same starting state the preset was named from. Dragging on the map or moving a slider keeps the current field instead, which is how you can grow coral and then push it into spots.

  2. 02

    Steps per frame. How many solver steps run between two screen refreshes. The step itself never changes size, so a higher setting is faster pattern growth, not a coarser simulation.

  3. 03

    Readouts. Coverage is the share of cells with V>0.1V > 0.1, the same threshold the presets were calibrated with. Mean V falls to zero when a pattern dies. Distance to curve is (F/2−F)−k(\sqrt{F}/2 - F) - k: positive is left of the saddle-node line, negative is right of it. Patterns form on both sides of zero; far into the negative, they die.

  4. 04

    The loop. On load the page runs a 2,000-step warm-up in short chunks so the first picture is already a pattern, then hands over to requestAnimationFrame. Two buffers swap every step. The loop stops stepping when the field scrolls out of view or the tab is hidden, and starts paused if your system asks for reduced motion.

Essence

Nothing in the equations says “spot” or “stripe”.

Two numbers per cell, one reaction, one blur. The same update runs on every cell, with no rule anywhere about shapes. Yet move the ring a short way across the map and the field that grew coral grows dividing spots instead.

Alan Turing proposed in 1952 that this is how a uniform embryo could break its own symmetry: one chemical that makes more of itself, another that spreads faster and holds it back. John Pearson’s 1993 survey of the Gray–Scott version mapped the zoo of shapes that live just inside one curve on the (k, F) plane. The map on the right is that plane, with the curve drawn on it.

The intuition: grow, starve, split

Start with a small patch of V in a sea of U. Inside the patch, the reaction U+2V→3VU + 2V \to 3V converts U into V, and the more V there is, the faster it goes. The patch grows.

But it eats the U around it. U diffuses in from outside at twice V’s rate, and the centre of a large patch is the farthest point from that supply. The centre starves first. A spot that grows too big pinches in the middle and becomes two spots: that is the Mitosis preset.

Meanwhile the whole grid is being washed: fresh U arrives at rate FF, and V is drained at F+kF + k. Turn kk up and V cannot outrun its own removal; everything fades. Turn it down and V wins everywhere and the field fills. The patterns are what happens in the narrow band where neither side wins outright.

Think of it like

A wildfire in grass that regrows. The fire spreads into fresh fuel and leaves ash behind. If the grass regrows fast, fronts march as rings; if it regrows slowly, fires break up into isolated patches that each burn out their own neighbourhood.

Why unequal diffusion matters

Here Dv/DuD_v / D_u = 0.50. If both chemicals spread at the same rate, a patch could never starve its own centre, and the field would smooth out instead of breaking into shapes.

The math, from PDE to the loop that runs

1. The equations

∂u∂t=Du∇2u−uv2+F(1−u)∂v∂t=Dv∇2v+uv2−(F+k)v\begin{aligned} \frac{\partial u}{\partial t} &= D_u \nabla^2 u - u v^2 + F(1 - u) \\ \frac{\partial v}{\partial t} &= D_v \nabla^2 v + u v^2 - (F + k) v \end{aligned}

The uv2uv^2 term is the reaction, taken from U and given to V. F(1−u)F(1-u) refills U toward 1. (F+k)v(F+k)v drains V. This page runs DuD_u = 1.0, DvD_v = 0.5, Δt\Delta t = 1.

2. The Laplacian on a grid

Each cell compares itself to its eight neighbours with a 3 × 3 stencil. Edge neighbours weigh 0.2, corners 0.05, the centre -1:

∇2u≈[0.050.20.050.2−10.20.050.20.05]∗u\nabla^2 u \approx \begin{bmatrix} 0.05 & 0.2 & 0.05 \\ 0.2 & -1 & 0.2 \\ 0.05 & 0.2 & 0.05 \end{bmatrix} * u

The weights sum to 0.0, so diffusion alone moves chemical around without creating or destroying any. Including the corners makes the blur more nearly the same in every direction than the plain five-point cross, which weighs the grid axes more than the diagonals.

3. One explicit Euler step

un+1=un+Δt (DuL[un]−unvn2+F(1−un))vn+1=vn+Δt (DvL[vn]+unvn2−(F+k) vn)\begin{aligned} u_{n+1} &= u_n + \Delta t\,\bigl(D_u L[u_n] - u_n v_n^2 + F(1 - u_n)\bigr) \\ v_{n+1} &= v_n + \Delta t\,\bigl(D_v L[v_n] + u_n v_n^2 - (F + k)\,v_n\bigr) \end{aligned}

Every cell reads the old buffer and writes the new one; the buffers then swap. That is the whole solver. The listing further down is the function, character for character, and a test runs it against the module the page imports.

The curve on the map

Set both time derivatives to zero with no diffusion and v≠0v \ne 0. Then uv=F+kuv = F + k, and substituting gives

(F+k) v2−Fv+F(F+k)=0(F+k)\,v^2 - F v + F(F+k) = 0

which has real roots only while F≥4(F+k)2F \ge 4(F+k)^2. The boundary of that region is

k=F2−Fk = \tfrac{\sqrt{F}}{2} - F

It peaks at F=1/16F = 1/16, where kk = 0.0625. Right of the curve the only uniform state is U=1,V=0U = 1, V = 0, and it is stable against small, spread-out disturbances. It is not stable against a strong local seed, which is why patterns live on both sides of the line: here Coral, Holes, Cells sit left of it and Mitosis, Solitons, Fingerprint, Rings, Worms sit right of it, Mitosis farthest at -0.0058.

Why Δt = 1 does not blow up

Explicit Euler on diffusion is stable while every grid mode shrinks. The fastest mode of this stencil is the checkerboard, whose eigenvalue is -1.6. One step multiplies a U checkerboard by −0.6 and a V checkerboard by +0.2: both smaller than 1 in size, so grid noise decays instead of growing. Raise DuD_u past 1.25 at this step and that would no longer be true.

Two worked examples

Both use the steady-state algebra from the curve card above, solved when the page is built from two of the presets, and checked in the site's test suite against a brute-force root scan, an ODE integration and this page's own simulator. Diffusion is off in both: they describe uniform sheets of chemistry, not patterns. Press either preset in the simulator above to watch what diffusion does with it.

A · Cells: a sheet the chemistry can rest in

F = 0.0620, k = 0.0609 (the Cells preset), 0.0016 left of the curve.

V±=F±F2−4F(F+k)22(F+k)=0.2925, 0.2119V_\pm = \frac{F \pm \sqrt{F^2 - 4F(F+k)^2}}{2(F+k)} = 0.2925,\ 0.2119
Curve k at this F
0.0625
Upper sheet V
0.2925
Upper sheet U
0.4201
Trace k − V²
−0.0247
Determinant (F + k)(V² − F)
0.0029
Lowest F with a sheet at this k
0.0441
Highest F with a sheet at this k
0.0841

Negative trace, positive determinant, and trace² below four times the determinant: the upper sheet is a stable focus. Knock it evenly and it spirals back. The lower root, V = 0.2119, is a saddle: nudged, it falls to the upper sheet or to empty. Why the Cells sheet then cracks into cells is diffusion's doing, which this calculation leaves out.

B · Mitosis: past the peak, no uniform sheet

F = 0.0367, k = 0.0649 (the Mitosis preset), 0.0058 right of the curve.

k=0.0649>max⁡F(F2−F)=116=0.0625k = 0.0649 > \max_F \left(\tfrac{\sqrt{F}}{2} - F\right) = \tfrac{1}{16} = 0.0625
Curve k at this F
0.0591
Distance to the curve
−0.0058
F values with a sheet at this k
none
Weak V wash, per step × (1 − F − k)
0.8984
Steps for the wash to halve
6.5 steps

Here 16k = 1.038, above 1, so no feed rate at all gives a uniform mixed state, and the only one left is empty: U = 1, V = 0. A thin, even wash of V shrinks by the factor above on every step. The spots Mitosis grows survive anyway because each is a concentrated patch, which is exactly the case a uniform analysis cannot see.

Playbook: what to try

Start here

Let Coral run, then scribble. Every stroke becomes a new growth front. Paint a closed loop and watch the branches inside and outside it compete for U.

Change chemistry mid-flight

Grow Coral, then drag the ring down toward Mitosis. The labyrinth breaks into beads, and the beads start dividing. Drag back up and they reconnect. The field keeps its history; only the rules changed.

Cross the line

Drag the ring deep into the shaded side, toward the bottom-right corner. Just past the curve patterns survive; far past it, watch Mean V fall to zero as the whole field dissolves. Drag back and nothing returns, because there is no V left to amplify; paint a stroke and it does.

Watch the edges

Paint near one side. The growth reappears on the opposite side, because the grid wraps. There is no wall to reflect from and no corner for patterns to pile into.

The presets, computed at build

PresetFkDistance to curve
Coral0.05450.0620+0.0002
Mitosis0.03670.0649−0.0058
Solitons0.03000.0620−0.0054
Fingerprint0.03700.0600−0.0008
Rings0.01800.0510−0.0019
Holes0.03900.0580+0.0017
Cells0.06200.0609+0.0016
Worms0.05800.0650−0.0026

All 8 were run from the page’s own seed and named for what actually formed. The textbook “waves” pair, F 0.014 and k 0.045, died out completely under this normalisation and is left out rather than relabelled.

Honesty: what this is and isn’t

What is exact

The equations are the Gray–Scott model as published, discretised with a standard 3 × 3 Laplacian and stepped with explicit Euler. The step shown below is the step that runs. The saddle-node curve and the preset distances are derived, not traced from a figure; the curve marks where uniform mixed states end, and the page does not claim it is where patterns end. The still image used for this page in the lab gallery is a screenshot of this canvas after its warm-up, taken in a headless browser; it is not a render or an illustration.

What it simplifies

Edges are periodic, so the field is a torus, not a dish. The units are Karl Sims’ normalisation, not Pearson’s dimensional constants; F and k carry over, the diffusion numbers do not. The time step is fixed with no adaptive stepping or error control. Concentrations are stored as 32-bit floats, so two runs on different machines agree only as far as their float rounding does. The grid is 256 cells across, coarse enough that the finest patterns are a few cells wide.

Two gotchas that matter

Parameter tables do not travel

Gray–Scott demos disagree on diffusion constants, stencils and step size, so an (F, k) pair that makes spots in one can make nothing in another. The “waves” pair above is the example: it is a fine preset elsewhere and a blank screen here. If you copy values from a table, check which normalisation it was written for, or run it and name it for what you see.

The seed is part of the result

Several regions of the map are bistable or slow: whether a seed grows, which shape it settles into, and how long that takes all depend on where the V started. Munafo’s “U-skate” point produces gliders from carefully shaped seeds; from this page’s seed it forms cells instead, so the preset is called Cells. A preset name is a claim about one starting state, not about the parameter pair forever.

The solver, in JavaScript

The step the page runs, with its TypeScript types removed. It takes the current field, writes the next one into a second buffer, and wraps at every edge. A test in this repository evaluates this listing and compares it against the imported module on random fields, number for number.

stepGrayScott (JavaScript)

// One explicit Euler step of Gray–Scott on a periodic grid (src/lib/reaction-diffusion.ts)
function stepGrayScott(field, next, params) {
  const { size, u, v } = field;
  const { feed, kill, diffuseU, diffuseV, dt } = params;
  const removal = feed + kill;
  const un = next.u;
  const vn = next.v;
  for (let y = 0; y < size; y++) {
    const up = (y === 0 ? size - 1 : y - 1) * size;
    const row = y * size;
    const down = (y === size - 1 ? 0 : y + 1) * size;
    for (let x = 0; x < size; x++) {
      const left = x === 0 ? size - 1 : x - 1;
      const right = x === size - 1 ? 0 : x + 1;
      const i = row + x;
      const uc = u[i];
      const vc = v[i];
      const lapU =
        -uc
        + 0.2 * (u[up + x] + u[down + x] + u[row + left] + u[row + right])
        + 0.05 * (u[up + left] + u[up + right] + u[down + left] + u[down + right]);
      const lapV =
        -vc
        + 0.2 * (v[up + x] + v[down + x] + v[row + left] + v[row + right])
        + 0.05 * (v[up + left] + v[up + right] + v[down + left] + v[down + right]);
      const reaction = uc * vc * vc;
      un[i] = uc + (diffuseU * lapU - reaction + feed * (1 - uc)) * dt;
      vn[i] = vc + (diffuseV * lapV + reaction - removal * vc) * dt;
    }
  }
}

Frequently asked questions

What is the Gray–Scott model?

Two chemicals, U and V, spread across a surface and react. U is fed in everywhere at rate F; V is removed at rate F + k; and wherever one V meets two U, the reaction U + 2V → 3V turns a U into another V. Because V makes more of itself but U diffuses twice as fast, a small patch of V can grow, starve its own surroundings of U and split. Those two ingredients, self-amplification and unequal diffusion, are enough to produce spots, stripes and labyrinths from an almost uniform start.

Why do my F and k values not match the numbers in Pearson’s 1993 paper?

They do match: F and k are the same axes. What differs is the diffusion constants and the time step. Pearson used D_u = 2×10⁻⁵ and D_v = 10⁻⁵ on a unit square; this page uses Karl Sims’ normalisation, D_u = 1, D_v = 0.5 and one step per time unit on a grid where one cell is one length unit. Rescaling length and time changes the diffusion numbers but leaves F and k untouched, which is why Pearson’s (k, F) map still reads here.

What does the curve on the map mean, and why do patterns grow on both sides of it?

The curve is the saddle-node line k = √F/2 − F. Left of it, the whole plane could sit in a uniform mixed state of U and V. Right of it, the only uniform state is U = 1, V = 0, so a weak, spread-out wash of V fades away. A strong, concentrated patch is different: it can sustain itself locally, which is why several presets sit just right of the curve and still form spots, worms and rings. Go far enough right and every seed dies; the region where most of Pearson’s patterns live is the thin band around the curve.

Is this running on the GPU?

No. Each step is a plain JavaScript double loop over a 256 × 256 Float32Array, the same function shown in the listing below. That keeps it working on every browser and phone and makes the displayed code testable against the code that runs. A GPU shader would allow a far larger grid; it would not change the chemistry.

Why do the presets keep changing after they look finished?

Some of them never finish. Coral keeps growing outward until it fills the plane, Rings never settles, and Mitosis keeps dividing until the spots are packed. The preset notes describe what forms from the page’s own seed in the first few thousand steps; leave any of them running long enough and the picture will drift.

Shareable still

The instrument, captured—not illustrated.

This 16:9 frame is rendered from the real browser instrument above. It is the page's canonical preview for image search, link unfurls, and posts that need to show what the tool actually does.

Download 1280 × 720 JPEG
Reaction–Diffusion Pattern Lab — live MakerPortal instrument screenshot
Canonical capture · real UI · no generated scientific artwork