reas_processing · grayScottRD
Gray-Scott Reaction-Diffusion
Two scalar species U and V diffuse on a square grid with rates Du and Dv and react with feed F and kill k. The system produces Turing patterns: spots, stripes, coral, solitons. Famous for being swept across (F, k) parameter space in Reas's Processing-era teaching and Jonathan McCabe's community demo, where a single parameter sweep reveals ten or more distinct morphologies.
Original: https://en.wikipedia.org/wiki/Reaction%E2%80%93diffusion_system
▶ Try the live demo (JS port) ▶ Run reference.py via Pyodide 10 formulas have instant JS ports. The Pyodide path runs the actual Python in your browser — first load is ~6 MB, then instant.
Math essence
dU/dt = Du*lap(U) - U*V*V + F*(1 - U); dV/dt = Dv*lap(V) + U*V*V - (F + k)*V. The isotropic 5-point + 4-diagonal 9-point Laplacian is computed with numpy.roll for periodic boundaries; integration is explicit Euler with clipping to [0,1].
Parameters
| Name | Type | Default | Range | Description |
|---|---|---|---|---|
dim | int | 256 | 64–600 | Square grid side length. |
Du | float | 1 | 0.1–2 | Diffusion rate of U. |
Dv | float | 0.5 | 0.1–1.5 | Diffusion rate of V. |
F | float | 0.0367 | 0.01–0.1 | Feed rate. |
k | float | 0.0649 | 0.03–0.075 | Kill rate. (F,k) pairs select morphology. |
dt | float | 1 | 0.5–2 | Time step. |
steps_per_render | int | 16 | 1–64 | Sub-steps inside one step(n=1) call. |
palette_mode | str | viridis | — | Color map for V: 'viridis', 'magma', 'ocean', or 'two_tone'. |
initial_seeds | int | 8 | 1–64 | Number of random initial V blobs. |
seed | int | null | 0–999999 | Optional seed for reproducible seed placements. |
Reference
First 60 lines of reference.py. Full source:
library_external/reas_processing/grayScottRD/reference.py
from __future__ import annotations
from typing import ClassVar
import numpy as np
class GrayScottRD:
"""Gray-Scott Reaction-Diffusion.
Two scalar species U and V diffuse on a square grid with rates Du and Dv
and react with feed rate F and kill rate k:
dU/dt = Du*lap(U) - U*V*V + F*(1 - U)
dV/dt = Dv*lap(V) + U*V*V - (F + k)*V
The system is the canonical Gray-Scott model from Pearson 1993, popular in
generative art since the early 2000s (it appears in the Processing
community's Reaction-Diffusion tutorials). Different (F, k) pairs produce
mitosis spots, stripes, coral, worms, solitons, and other Turing patterns.
"""
family: ClassVar[str] = "reas_processing"
sketch: ClassVar[str] = "grayScottRD"
def __init__(
self,
dim: int = 256,
Du: float = 1.0,
Dv: float = 0.5,
F: float = 0.0367,
k: float = 0.0649,
dt: float = 1.0,
steps_per_render: int = 16,
palette_mode: str = "viridis",
seed: int | None = None,
initial_seeds: int = 8,
) -> None:
self.dim = dim
self.Du = Du
self.Dv = Dv
self.F = F
self.k = k
self.dt = dt
self.steps_per_render = steps_per_render
self._palette_mode = palette_mode
self.initial_seeds = initial_seeds
self._seed = seed
self.reset()
def reset(self, seed: int | None = None) -> None:
if seed is not None:
self._seed = seed
self.rng = np.random.default_rng(self._seed)
self.U = np.ones((self.dim, self.dim), dtype=np.float32)
self.V = np.zeros((self.dim, self.dim), dtype=np.float32)
n = self.initial_seeds
cx = self.rng.integers(self.dim // 4, 3 * self.dim // 4, size=n)
cy = self.rng.integers(self.dim // 4, 3 * self.dim // 4, size=n)
rad = np.arange(-3, 4) Try running it locally
The reference implementation is self-contained Python with numpy. Install the package and run:
python library_external/reas_processing/grayScottRD/reference.py Need help? See Learn for the standard environment setup, or Playground for an in-browser sketchbook.
More from reas · processing
2-D Totalistic Cellular Automaton (Conway + variants)
reas_processing · wolframCA2D
Each cell looks at its 8 Moore neighbors and applies a totalistic rule.
Lindenmayer L-system + Turtle Rendering
reas_processing · lindenmayer
An axiom string is rewritten by parallel production rules for a fixed number of iterations, then interpreted by a 2-D turtle: 'F' walks forward, '+/-' turn left/right, '['/']' push/pop state.
Particle-Spring Cloth (Verlet + Hooke)
reas_processing · particleSpring
A rectangular grid of free particles is connected by Hooke's-law springs at rest length 'spacing'.
Perlin Streamlines
reas_processing · perlinStreamlines
A 2-D vector field is sampled from one or more octaves of Perlin gradient noise.
Voronoi Diagram from Random Seeds
reas_processing · voronoi
Every pixel on the canvas is colored with the palette color of the seed point closest to it.
Wolfram Elementary 1-D Cellular Automaton
reas_processing · wolframCA1D
Each row of the canvas is one generation of a Wolfram elementary cellular automaton.