technique

Reaction diffusion

Simulate two diffusing, reacting chemicals across a 2D grid using the Gray-Scott model to grow organic Turing-pattern textures.

Also called: Reaction Diffusion Algorithm · Reaction-diffusion · Gray-Scott model

What it is

Reaction-diffusion — recorded in the corpus as a synonym of the Gray-Scott model, and also just called the reaction diffusion algorithm — simulates two chemicals, conventionally named a and b, that diffuse across a 2D grid and react with each other wherever they meet. Run for enough steps, the interplay between diffusion and reaction settles into the mottled, organic textures usually called Turing patterns — the category of image people actually mean when they say something “looks like reaction-diffusion.” The technique is recorded here with two runtimes: p5.js, the way Coding Train’s challenge builds it on a canvas of pixels, and a GLSL fragment shader, the way the Book of Shaders’ version runs it on the GPU.

How it works

Coding Train’s challenge notes for this technique call out five separate pieces to build. Here they are in the order you’d actually wire them into a running loop — not necessarily the order the notes list them in:

  1. Grid setup. Store the amount of chemical a and chemical b at every cell — Coding Train’s version keeps this per pixel of the canvas. You need a current grid and a next grid, so you’re never overwriting a value you still need to read this step.
  2. Seed. Fill one whole region of the grid with chemical b, rather than starting from noise. This seeded patch is the only initial condition the notes call out explicitly, and it’s what the pattern grows outward from.
  3. Diffusion. For every cell, add the Laplace calculation for both a and b.
  4. Reaction. Combine each cell’s Laplacian with the Gray-Scott reaction formulas, and write the result into the next grid.
  5. Swap. Once every cell is updated, swap current and next, and repeat.

That’s the whole loop the evidence describes.

Parameters & tuning

The two knobs that actually decide what you see — the diffusion rates for a and b, and the feed/kill rates that drive the reaction term — are exactly the ones this bundle gives no number for. The excerpts confirm that diffusion and reaction are separate stages of the loop, and that the model is the Gray-Scott model by name, but neither the Coding Train notes nor the Book of Shaders excerpt supplied here state what values go into either stage. Treat that as the actual task if you’re building this tonight: go read Karl Sims’ Reaction Diffusion Tutorial — credited directly as the source Coding Train’s challenge was built from — or the Book of Shaders chapter, rather than guessing a feed/kill pair from memory. Different pairs put the simulation in different regimes — something like spots, something like worms, or nothing at all, a flat field that never differentiates — and nothing in this bundle tells you where those boundaries sit.

The one parameter this bundle does describe is the seed: where you place that filled region, and how large it is, is called out as its own step. What different seed sizes or placements actually produce isn’t described here.

Where it’s been used

The only named references in the evidence for this page are the two sources the technique itself is reconstructed from: Karl Sims’ Reaction Diffusion Tutorial, credited in Coding Train’s own challenge notes, and the reaction-diffusion chapter of Patricio Gonzalez Vivo and Jen Lowe’s Book of Shaders. No specific artwork or artist’s use of the technique appears in the evidence supplied here — that’s a gap, not an omission.

Variants & neighbours

Worth naming so you don’t reach for reaction-diffusion when one of these is actually what you want: Gift wrapping algorithm builds a convex hull by repeatedly picking the next boundary point that keeps every other point to one side — a single deterministic pass over a fixed point set, with no time-stepped state at all. Cohen-Sutherland line clipping trims a line segment to a rectangular viewport using outcodes — again one deterministic pass, not a simulation. Genetic algorithm does hold state across iterations the way reaction-diffusion does, but that state is a population of discrete candidates moving toward a target under fitness-weighted selection and crossover, not a continuous concentration field diffusing under a fixed local rule. None of the three are close relatives of reaction-diffusion; they’re useful mainly as a reminder that “grows something over many steps” isn’t one algorithm.

Go deeper

This page draws on two sources: Coding Train’s Reaction-Diffusion coding challenge (numbered 13 in its own URL, and dated in the corpus to 2016), and the reaction-diffusion chapter of the Book of Shaders, linked above. Coding Train’s notes credit Karl Sims’ Reaction Diffusion Tutorial as what the challenge was built from — worth reading first if you want the original formulation rather than a derivative walkthrough. Neither Sims’ tutorial nor the Book of Shaders is currently linked as a registered entity from this page; treat both as real, findable things to go read next rather than a citation the graph can walk for you yet.

Connected to

Further reading: The Book of Shaders


Revision 2 · 2 sources · Something wrong? Tell us.