Skip to content
Sample of Reaction Diffusion (Gray-Scott)

complexification_net · reactionDiffusion

Reaction Diffusion (Gray-Scott)

Gray-Scott reaction-diffusion on a torus: two virtual chemicals U (substrate) and V (catalyst) react and diffuse on a 2D grid. V catalyzes U→V at rate U·V², U is replenished at rate feed·(1-U), and V decays at rate (feed+kill)·V. Diffusion is implemented with the 4-neighbor Laplacian stencil. The default F=0.055, k=0.062 parameter set lands in Pearson's 'mitosis' regime — circular V-bubbles grow, deform, and split into pairs that swim outward. Six presets are exposed: mitosis, spots, stripes, coral, maze, flicker — each corresponds to a different region of (F, k) parameter space.

Original: https://web.archive.org/web/20041229124929/http://www.levitated.net:80/daily/indexCategory.html

▶ 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
complexification_net
Source
complexification.net
Evolution
reaction_diffusion
Render
raster_indexed
Complexity
high
Agents
1
Year
2004
Author
j.tarbell (style)

Math essence

Gray-Scott PDE on a periodic grid: U_{t+1} = U + dt·(Du·∇²U − UV² + F·(1−U)), V_{t+1} = V + dt·(Dv·∇²V + UV² − (F+k)·V). The 4-neighbor Laplacian is ∇²U = U_N + U_S + U_E + U_W − 4U. The bistable (F, k) parameter space yields Turing patterns: spots that propagate, stripes that wind, mazes that fill, and mitosis-like cell division.

Parameters

Name Type Default Range Description
dim int 256 100–600 Square grid side length
feed float 0.055 0.005–0.1 Feed rate of U
kill float 0.062 0.03–0.075 Decay rate of V
Du float 0.16 0.05–0.3 Diffusion constant of U
Dv float 0.08 0.02–0.2 Diffusion constant of V
dt float 1 0.5–1.5 Euler time step
seed_patches int 8 1–64 Number of seed patches placed at reset
seed_radius int 6 1–30 Radius of each seed patch
palette str ink null–null Palette name (ink / rust / coral)
seed int null 0–999999 RNG seed

Reference

First 60 lines of reference.py. Full source: library_external/complexification_net/reactionDiffusion/reference.py

from __future__ import annotations

from typing import ClassVar

import imageio.v2 as imageio
import numpy as np


_PALETTES: dict[str, np.ndarray] = {
    "ink": np.array(
        [
            [10, 10, 20],
            [30, 30, 50],
            [60, 60, 90],
            [95, 95, 130],
            [130, 130, 170],
            [170, 165, 200],
            [210, 200, 220],
            [240, 230, 235],
            [255, 255, 255],
            [240, 220, 195],
            [220, 180, 150],
            [200, 140, 110],
            [180, 100, 75],
            [150, 70, 50],
            [110, 50, 35],
            [70, 35, 25],
        ],
        dtype=np.uint8,
    ),
    "rust": np.array(
        [
            [25, 12, 8],
            [60, 22, 8],
            [110, 38, 12],
            [165, 60, 18],
            [210, 90, 30],
            [240, 130, 50],
            [255, 175, 80],
            [255, 220, 130],
            [255, 248, 200],
            [220, 240, 220],
            [180, 220, 220],
            [140, 195, 210],
            [100, 160, 195],
            [60, 120, 170],
            [30, 80, 130],
            [10, 40, 80],
        ],
        dtype=np.uint8,
    ),
    "coral": np.array(
        [
            [10, 30, 50],
            [20, 60, 80],
            [40, 100, 110],
            [80, 140, 130],
            [130, 180, 140],
            [180, 210, 150],
            [230, 235, 165],

Try running it locally

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

python library_external/complexification_net/reactionDiffusion/reference.py

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

More from complexification.net

See all complexification_net artworks →