Gray–Scott Reaction-Diffusion: Feed, Kill, and Demo Controls

15 min read
MathematicsSimulationCanvas APIReaction-Diffusion

The Gray–Scott model is a reaction-diffusion system in which u is supplied, the reaction converts u into more v, and v is removed. Both substances diffuse. The feed rate f and kill rate k affect the states the calculation can reach.

Open the Gray–Scott reaction-diffusion demo to choose four presets and place seeds on the canvas. Keep the same preset and compare a run with only the central circular seed against one in which you add a seed elsewhere while the calculation is running.

On November 17, 2026, the time stepping was corrected to address a numerical breakdown in the concentration calculation. This guide connects the controls, feed/kill equations, and corrected update method. Preset names do not guarantee particular shapes, and the demo is not a tool for reproducing or measuring a chemical experiment.

Choose a preset and place seeds

The controls are the four preset buttons and Reset at the bottom of the canvas, plus pointer input on the canvas. There are no sliders for entering arbitrary f / k values.

  1. Choose a preset such as Spots. Each selection initializes the concentration grid and places a seed at its center.
  2. Press inside the canvas. A seed is added at the pointer while it remains pressed. Drag while holding to move that position.
  3. Press Reset to start again with the same preset. It reinitializes the concentration grid without changing the selection.

Switching presets discards the previous state. It does not turn the existing spots into stripes. Initialization and seed placement also use random numbers, so Reset does not reproduce an identical concentration field each time.

Preset name Feed rate f Kill rate k
Spots 0.055 0.062
Stripes 0.035 0.065
Coral 0.060 0.062
Mitosis 0.0367 0.0649

These are the names of the settings registered in the demo. Spots and Coral, for example, share k and differ only in f. Both values differ between Stripes and Mitosis, so a difference between those runs cannot be attributed to feed rate alone. Do not assume that selecting a name guarantees spots, stripes, or branching shapes. Observe how regions of higher concentration spread and how adding a seed changes its surroundings.

What do feed and kill change in the Gray–Scott model?

Each cell holds concentrations u and v. The reaction consumes u and produces v; v participates in producing more of itself, which is called autocatalysis. Karl Sims's tutorial describes the reaction as A + 2B → 3B. Here, A corresponds to u, and B to v.

The continuous model has the following form:

∂u/∂t = Du·∇²u − u·v² + f(1 − u)
∂v/∂t = Dv·∇²v + u·v² − (f + k)·v
  • Du·∇²u and Dv·∇²v are diffusion terms that spread concentration differences through space.
  • u·v² is the reaction term, decreasing u and increasing v.
  • f(1 − u) supplies u, moving it toward the reference concentration of 1.
  • (f + k)·v removes v. It includes the feed rate f as well as the kill rate k.

Changing f therefore changes both supply and removal. It does not follow that increasing feed must make a pattern larger. Initial seeds, diffusion coefficients, boundary conditions, and the numerical method also matter.

John E. Pearson's original paper reports varied patterns in reaction-diffusion simulations, including spots that grow and divide. Evidence that the model can form patterns is separate from evidence that every setting in this demo reproduces them.

What is calculated on the 200×200 grid?

The demo uses 40,000 cells. It stores u, v, and their next-step destinations in four Float32Array buffers. Swapping the read and write buffers after an update avoids reading values that have already changed during that same update.

Implementation setting Value or method
Grid 200×200
Diffusion coefficients Du = 1.0, Dv = 0.5
Time step Base DT = 0.2, with a shared dt further limited by concentrations and coefficients
Updates per rendered frame 6 steps
Spatial approximation Five-point Laplacian: center and four orthogonal neighbors
Boundary Periodic: opposite edges are connected

Writing the center concentration as uC and its neighbors as uLeft, and so on, gives the following implementation equations. Grid spacing is treated as 1.

lapU = uLeft + uRight + uUp + uDown − 4·uC
lapV = vLeft + vRight + vUp + vDown − 4·vC

nextU = uC + dt·(Du·lapU − uC·vC² + f·(1 − uC))
nextV = vC + dt·(Dv·lapV + uC·vC² − (f + k)·vC)

An edge cell uses the opposite edge as a neighbor. The simulated region wraps horizontally and vertically; these are not reflecting walls.

The initial central seed has a radius of 10 cells. A pointer seed has a radius of 5 cells. In normal display use, both write values calculated as u = 0.5 + Math.random() * 0.02 and v = 0.25 + Math.random() * 0.02 into their circular region. Pointer input changes the concentrations used in the calculation, rather than simply drawing a visible dot.

How the time step was corrected

The corrected implementation finds the maximum v across the grid before each update and uses one shared time step, dt, for all cells. It starts with a base value of 0.2 and applies these additional bounds:

maxV = max(v)
dt = min(0.2, 0.9 / (4·Du + maxV² + f), 0.9 / (4·Dv + f + k))

These bounds prevent the coefficient of concentration retained in a cell from becoming negative through diffusion, reaction, supply, or removal. The implementation groups the update into nonnegative terms. This assumes finite 0 ≤ u ≤ 1, v ≥ 0, and the current positive preset coefficients. Inputs are checked rather than continuing a calculation with invalid concentrations.

A shared time step, rather than a different step per cell, preserves the accounting of quantities diffusing across the periodic grid. The implementation does not clip concentrations to 0–1 to produce its patterns. Floating-point rounding remains; these conditions alone do not prove stability for infinite time or every interaction, nor the accuracy of the solution to the continuous equations.

The implementation still runs six updates per rendered frame. dt is a model time step, not elapsed browser seconds. FPS and seconds until a particular pattern appears have not been measured.

What went wrong with the previous DT=1?

The previous implementation applied DT = 1.0 to the same five-point Laplacian. Consider v = 0, f = 0.055, and a checkerboard of u = 0.9995 and u = 0.9985 on the 200×200 periodic grid. One application of the old update in real arithmetic gives approximately 0.9955275 and 1.0025825: the difference between neighboring values reverses sign and grows by a factor of about 7.055. The reaction term u·v² is zero in this state, so reaction terms cannot justify that large time step.

The old implementation also broke down when starting from the central seed without pointer input. Fixing the random return value at 0, 0.5, and 0.999999 and combining them with the four presets gave 12 conditions. All 12 produced non-finite values after 12 updates. Those are results from the previous implementation, not the behavior of the current demo.

Karl Sims's tutorial uses a weighted Laplacian that includes diagonal neighbors. It differs from this demo's five-point formula. Matching the numbers for Du, Dv, and DT alone does not transfer numerical stability between methods.

The display maps v into a 256-entry color table. Its color index is limited to 0–255, which is separate from limiting concentrations. Correcting the numerical calculation requires changing its concentration update and time step, rather than restricting colors.

Keep comparison conditions clear

Record the preset name, where and how seeds were placed, and whether the grid was reinitialized. Do not attribute every visual difference to feed and kill; randomness and numerical settings also affect the result. In particular, a run with only the central circular seed and one with seeds added elsewhere during the calculation can give different observations under the same preset.

Reproducing an identical concentration field requires controlling randomness and interactions. The current UI does not fix a random seed or scan arbitrary f / k values. After trying the four settings, Karl Sims's parameter map provides a wider view of model patterns. Its numerical method differs from this demo, so an identical shape should not be assumed.

Go deeper on this topic

Creative Coding

Mathematical simulations, nature visualization, and generative art in the browser

Article 7 of 13 in this series.

View topic page

Use the topic hub as a map, then continue to the next article in the series. New here? Start at the home hub →