Visualizations
240 / 500

240 · Emergence

Turing Patterns

Two chemicals react and diffuse into coral, spots and stripes.

A Gray-Scott reaction-diffusion model tracks two virtual chemicals on a grid. Each step, both diffuse to neighbors at different rates, one consumes the other, and the second is replenished from outside. Those few rules grow organic patterns like the ones Alan Turing proposed for animal markings. The grid lives in typed arrays and is painted into ImageData with a color ramp.

Try it. Drag to drop new chemical seeds. Click the view, then press 1 to 4 to switch between coral, spots, worms and mitosis, or R to reseed.

  • Reaction-diffusion
  • Typed arrays
  • Laplacian convolution

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a Gray-Scott reaction-diffusion simulation with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window and resizes with it. Simulate on a small grid (about 256 x 160 cells) and scale it up to fill the screen with drawImage.
- Keep two chemicals, A and B, in Float32Arrays. Start with A = 1 and B = 0 everywhere, then drop 20 or so small square seeds of B = 1 at random spots.
- Each step, compute the Laplacian with a 3x3 kernel (center -1, edges 0.2, corners 0.05) and wrap around the edges. Update with dA = 1.0 * lapA - A*B*B + feed*(1 - A) and dB = 0.5 * lapB + A*B*B - (feed + kill)*B, using two buffers you swap.
- Start with feed = 0.055 and kill = 0.062. Run about 10 steps per animation frame so the pattern grows quickly.
- Draw B into an ImageData buffer on an offscreen canvas, then draw that scaled up.
- Let the mouse paint new B seeds while dragging.

Once that works, make it beautiful:
- Replace grayscale with a color ramp lookup table (say deep navy, teal, coral, cream) precomputed into a Uint32Array so each pixel is one array write.
- Add fake emboss lighting by brightening or darkening each pixel using the difference of B between its upper-left and lower-right neighbors.
- Add presets on the number keys: coral (0.0545, 0.062), spots (0.03, 0.062), worms (0.078, 0.061) and mitosis (0.0367, 0.0649), and ease feed and kill toward the new values so patterns morph.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as letting feed and kill vary across the screen, running the simulation on the GPU, or seeding it from text or an image.
PreviousMarimba Bar TunerCarve a rosewood bar while a finite element solver retunes its overtones to 1:4:10. NextWythoff KaleidoscopeOne draggable seed in a mirror triangle generates every convex uniform polyhedron.

Related visualizations

  • Falling SandSimulation Sand, water, fire, lava and plants that all react with each other.
  • LeniaEmergence Smooth artificial life: glowing creatures that glide, spin and divide.
  • Seashell PatternsNature Meinhardt's lip chemistry paints tents, bands and dots onto a growing 3D shell.
  • Differential GrowthGenerative art One closed line grows, buckles and folds into brain coral without ever crossing.
  • Particle LifeEmergence Colored particles with simple attractions that assemble into living cells.
  • Slime MoldEmergence Simple agents leave trails that self-organize into living networks.
  • Diffusion SketchpadMachine learning A diffusion model trains live and condenses pure noise into whatever shape you draw.
  • Rock Paper LizardsEmergence Three lizard morphs chase each other in spirals until mobility tips them into extinction.
  • Self-Replicating LoopsEmergence Langton's 1984 loops copy their own genome and tile the plane with a glass colony.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs