← ⚗️ Chemistry

🧫 Reaction-Diffusion

Gray-Scott model
Presets
Colour palette
Grid256 × 256
Steps/frame8
Click / drag — seed B substance · Panel — adjust parameters

About the Gray-Scott Reaction-Diffusion Model

This simulation runs the Gray-Scott reaction-diffusion system on a 256 by 256 grid, computed entirely on the GPU as WebGL fragment shaders. Two virtual chemicals, A and B, diffuse across the grid and react through A + 2B to 3B. The dynamics follow the coupled equations dA/dt = Da*lap(A) - A*B*B + f*(1-A) and dB/dt = Db*lap(B) + A*B*B - (k+f)*B, where the Laplacian is evaluated with a weighted nine-point stencil and B diffuses at half the rate of A.

The feed-rate slider (f, 0.01 to 0.1) sets how fast chemical A is replenished, while the kill-rate slider (k, 0.04 to 0.075) sets how fast B is removed; together they select whether spots, stripes, mazes or self-replicating blobs emerge. The Speed control sets simulation steps per frame (1 to 20), presets jump to known f/k combinations, and clicking or dragging injects substance B. The same self-organising mathematics is thought to underlie animal coat markings, seashell pigmentation and embryonic digit spacing, making it a cornerstone of mathematical biology.

Frequently Asked Questions

What is the Gray-Scott reaction-diffusion model?

It is a mathematical model of two chemicals, A and B, that spread out and react with one another. From these simple local rules complex patterns self-organise across the grid, including spots, stripes, labyrinths and spirals. It is a classic example of a Turing pattern, where order emerges spontaneously from diffusion and reaction.

How does the simulation actually compute the patterns?

The screen is a 256 by 256 grid where each cell stores concentrations of A and B inside a WebGL float texture. A fragment shader updates every cell in parallel each step using a ping-pong pair of render targets. The Speed slider runs between 1 and 20 of these steps per animation frame so the pattern evolves quickly.

What do the feed rate and kill rate sliders do?

The feed rate f controls how quickly chemical A is replenished into every cell, and the kill rate k controls how quickly chemical B is removed. Together these two numbers decide which family of patterns forms. Small changes can shift the system from steady spots to growing stripes or wandering mazes.

What is the underlying equation?

The two coupled partial differential equations are dA/dt = Da*lap(A) - A*B*B + f*(1-A) and dB/dt = Db*lap(B) + A*B*B - (k+f)*B. Here lap is the Laplacian representing diffusion, Da and Db are diffusion rates, and the A*B*B term is the autocatalytic reaction A + 2B to 3B. In this simulation Da is 1.0 and Db is 0.5.

Why does chemical B diffuse more slowly than chemical A?

The contrast in diffusion rates is essential. Here A spreads at rate 1.0 while B spreads at 0.5, so the activator B stays locally concentrated while the substrate A replenishes the surroundings. This short-range activation paired with long-range inhibition is exactly the condition Turing identified for stable patterns to form rather than washing out into a uniform mix.

What do the preset buttons set?

Each preset loads a known pair of f and k values and reseeds the grid. The presets are Coral (f 0.0545, k 0.062), Mitosis (f 0.0367, k 0.0649), Spots/Worms (f 0.030, k 0.062) and Maze (f 0.029, k 0.057). They are convenient starting points because the pattern type is highly sensitive to small parameter changes.

How do I seed or reset the pattern?

Clicking or dragging on the canvas injects extra chemical B at the cursor, letting you draw new growth by hand. The Reset grid button reseeds A=1 and B=0 with a few random B squares near the centre. Add seed drops a fresh random blob, and the pause button freezes the evolution so you can study a frozen pattern.

Is this simulation physically accurate?

It faithfully solves the Gray-Scott equations using an explicit time-step and a nine-point Laplacian, so the qualitative pattern families are correct. However, it is an idealised dimensionless model rather than a fit to any specific real chemical reaction, and the grid wraps around at its edges. It is a teaching and exploration tool, not a quantitative chemistry predictor.

Why do patterns sometimes self-replicate or die out?

In certain f and k regions a spot of B grows until it becomes unstable, then splits into two, mimicking cell division. In other regions the kill term overwhelms production and B fades to zero, leaving a blank field. These behaviours arise purely from the balance between the autocatalytic A*B*B reaction and the feed and kill terms.

What real-world phenomena does this relate to?

Reaction-diffusion mathematics is thought to shape animal coat markings such as leopard spots and zebra stripes, the pigmentation of seashells, and the spacing of fingers and toes in developing embryos. Alan Turing proposed this idea in his 1952 paper on morphogenesis, and in 2012 biologists confirmed Turing-like chemistry sets out digit spacing in mouse paws.

Why does the pattern look different each time I reset?

The seeding shader places a few squares of chemical B at slightly randomised positions near the centre using a hash function. Because the system is highly sensitive to initial conditions, these small random seeds grow into different but statistically similar arrangements each run, while the overall pattern family stays fixed by f and k.

What It Demonstrates

Reaction–diffusion systems model two chemical species U and V that react and diffuse at different rates. The Gray–Scott model used here produces Turing patterns: spots, stripes, mazes and self-replicating spots — the same mathematics that governs animal coat patterns, sand-dune formation, and embryonic development. Two parameters — feed rate F and kill rate k — control which pattern emerges.

How to Use

The simulation runs on the GPU as a WebGL fragment shader — it updates thousands of cells per frame in parallel. Click to seed species V at the cursor. Drag the F slider (feed rate) to change pattern type: low F → mazes; medium F → spots; high F → waves. The k slider (kill rate) controls spot replication. Pause, then adjust parameters to watch patterns metamorphose from one type to another.

Did You Know?

Alan Turing published "The Chemical Basis of Morphogenesis" in 1952 — two years before his death — proposing that reaction-diffusion could explain biological pattern formation. It was largely ignored for decades. In 2012, biologists confirmed Turing-like patterns directly in mouse embryo digit formation. The mathematics of a 1952 paper shapes every finger you have.