Skip to content
Sample of Gray-Scott Reaction-Diffusion

toxi_openframeworks · ReactionDiffusionGS

Gray-Scott Reaction-Diffusion

The canonical two-species Gray-Scott reaction-diffusion model on a periodic square grid: dU/dt = Du*lap(U) - U*V^2 + F*(1-U), dV/dt = Dv*lap(V) + U*V^2 - (F+k)*V. Different (F, k) pairs produce spots, stripes, mitosis, solitons, and coral. The 9-point Laplacian uses 4 axial + 4 diagonal neighbors weighted 0.2/0.05, integrated with explicit Euler. This is the same formulation used in `ofxReactionDiffusion` (matsune), Karsten Schmidt's toxiclibs R-D toy, and countless oF demo patches.

Original: https://github.com/matsune/ofxReactionDiffusion

▶ 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.

Family
toxi_openframeworks
Source
toxi · openFrameworks
Evolution
pde
Render
false_color_2d_field
Complexity
medium
Agents
0
Year
2010
Author
John Pearson (model, 1993); oF community / toxiclibs ports

Math essence

Laplacian via numpy.roll with weights (axial: 0.2, diagonal: 0.05). Explicit Euler integration, U and V clipped to [0, 1] each sub-step. Boundary is periodic (roll handles wrap-around). Output is the V field mapped through one of five palettes (viridis, magma, ocean, pearl, gray).

Parameters

Name Type Default Range Description
dim int 192 96–512 Square grid side length in pixels.
Du float 1 0.2–1.6 Diffusion rate of U.
Dv float 0.5 0.1–1 Diffusion rate of V.
F float 0.0367 0.005–0.1 Feed rate of U.
k float 0.0649 0.03–0.075 Kill rate of V.
dt float 1 0.5–2 Explicit-Euler time step.
steps_per_render int 24 1–80 Sub-steps inside one step(n=1) call.
seed_count int 9 0–32 Number of starting V blobs.
seed_radius float 3 1–10 Radius (px) of each seed blob.
palette_mode str viridis — False-color palette applied to V.
preset str null — If set, overrides (F, k) with one of Pearson's morphologies.
seed int null 0–999999 RNG seed for initial seed-blob positions.

Reference

First 60 lines of reference.py. Full source: library_external/toxi_openframeworks/ReactionDiffusionGS/reference.py

from __future__ import annotations

from typing import ClassVar

import numpy as np


_GS_PRESETS = {
    "spots": (0.0367, 0.0649),
    "stripes": (0.0545, 0.062),
    "solitons": (0.018, 0.051),
    "mitosis": (0.0367, 0.06),
    "coral": (0.0625, 0.0609),
}


class ReactionDiffusionGS:
    """Gray-Scott reaction-diffusion on a 2-D float grid.

    Two scalar species U, V diffuse on a periodic square grid and react
    via:

        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 (Pearson 1993) and is
    a staple of the oF community — `ofxReactionDiffusion` by Atsushi
    Tadokoro, Robert Hodgin's early R-D patches, and Schmidt's
    toxiclibs R-D toy ports all use this same pair of PDEs.

    The Laplacian uses a 9-point stencil (4 axial + 4 diagonal
    weighted 0.05) on a periodic grid via `numpy.roll`, integrated
    with explicit Euler. Different (F, k) pairs produce spots,
    stripes, mitosis, solitons, and coral.
    """

    family: ClassVar[str] = "toxi_openframeworks"
    sketch: ClassVar[str] = "reactiondiffusiongs"

    def __init__(
        self,
        dim: int = 192,
        Du: float = 1.0,
        Dv: float = 0.5,
        F: float = 0.0367,
        k: float = 0.0649,
        dt: float = 1.0,
        steps_per_render: int = 24,
        seed_count: int = 9,
        seed_radius: float = 3.0,
        palette_mode: str = "viridis",
        preset: str | None = None,
        seed: int | None = None,
    ) -> None:
        self.dim = dim
        self.Du = Du
        self.Dv = Dv
        self.F = F
        self.k = k
        self.dt = dt

Try running it locally

The reference implementation is self-contained Python with numpy. Install the package and run:

python library_external/toxi_openframeworks/ReactionDiffusionGS/reference.py

Need help? See Learn for the standard environment setup, or Playground for an in-browser sketchbook.

More from toxi · openFrameworks

Sample of Generative Type Letterforms

Generative Type Letterforms

toxi_openframeworks · GenerativeTypeLetterforms

Letterforms assembled from a 9×9 stroke grid alphabet (A–Z subset), then modulated by a parametric function (bar widths and stroke positions follow `a * sin(b*x + c)` style curves) and optionally recursively subdivided into smaller marks.

View →
Sample of Median-Cut Color Quantizer

Median-Cut Color Quantizer

toxi_openframeworks · ColorQuantizer

Heckbert's 1982 median-cut color quantization applied to an evolving procedural gradient + low-resolution noise wash.

View →
Sample of Pixel Sort (Glitch Art)

Pixel Sort (Glitch Art)

toxi_openframeworks · PixelSort

Per-row pixel sorting à la Kim Asendorf's `ASDFPixelSort` and Karsten Schmidt's own glitch-art Processing sketches.

View →
Sample of Sound-Reactive Particle Field (Synthetic Audio)

Sound-Reactive Particle Field (Synthetic Audio)

toxi_openframeworks · SoundReactiveField

Particles advected by a force field whose horizontal component is driven by a synthetic audio signal: a chain of N sinusoids at different frequencies/amplitudes (the 'audio'), with the audio's instantaneous value plus its time derivative ('beat onset') driving the field.

View →
Sample of Verlet Particle-Spring Network

Verlet Particle-Spring Network

toxi_openframeworks · ParticleSpring2D

A Verlet-integrated particle network connected to its k-nearest neighbours by Hooke's-law springs.

View →
Sample of Voronoi Tessellation with Lloyd Relaxation

Voronoi Tessellation with Lloyd Relaxation

toxi_openframeworks · VoronoiRelaxation

Lloyd's algorithm applied to a jittered point cloud: each seed is replaced with the centroid of its Voronoi cell, repeatedly, producing ever-more-uniform polygonal cells.

View →

See all toxi_openframeworks artworks →