Reaction–Diffusion Canvas: Grow Turing Patterns
Build a deterministic Gray–Scott field, verify its stencil and checkpoints independently, then bind the solver recipe, palette, and raster into one edition receipt.
Reaction–diffusion Canvas turns a compact Gray–Scott update into richly branching generative texture, but an attractive raster is not evidence that the solver is correct. This tutorial fixes the grid, seed, stencil, boundary, timestep, and palette; verifies selected states with a separate oracle; and exports the resulting edition with its receipt.
Reaction–diffusion Canvas needs a drawable contract
Reaction–diffusion Canvas art becomes reproducible when the equations, grid, boundary rule, seed, timestep, palette, and raster are treated as one edition. This tutorial builds a fixed 64×64 Gray–Scott study, verifies selected updates with a separate stencil, and exports the picture beside a receipt. It is a numerical artwork, not a claim about living tissue.
The grid stores concentrations U and V. At each cell, diffusion spreads each field through a finite-difference Laplacian while the reaction term consumes U and grows V. Feed restores U; kill removes V. The equations are open because feed and kill exchange material with an environment, so a conservation assertion would be false. That openness belongs in every reaction–diffusion Canvas receipt.
Make the limits concrete before drawing: dimensions are fixed, parameters come from a small safe range, timestep is bounded, concentration values are clamped only under a declared policy, and the simulation stops after a known number of steps. A deterministic seed places the initial V perturbation. Double buffers keep reads from the old state separate from writes to the new state.
This contract distinguishes the study from Lenia’s continuous cellular dynamics. Both can make organic fields, but their state variables, update laws, and evidence are different. The visual resemblance is an invitation to inspect the model, not permission to merge their claims.
- The center weight is −1.00.
- Four axial neighbors contribute +0.20 each.
- Four diagonal neighbors contribute +0.05 each.
- Wrap is one declared boundary rule; zero stencil sum is not full-system conservation.
Reading rule: labels, values, shapes, order, and line styles carry the conclusion; color is supplementary.
Discretize the Laplacian without directional artifacts
A common nine-cell stencil assigns −1 to the center, 0.2 to the four axial neighbors, and 0.05 to the four diagonal neighbors. The weights sum to zero, so a spatially constant field has a zero discrete Laplacian before reaction, feed, and kill terms are applied. That local check is useful; it is not a conservation law for the full system.
Every neighbor lookup must follow one boundary policy. Wrap boundaries connect opposite edges into a torus. Clamp boundaries repeat the edge cell. Either can be valid for an artwork, but mixing them at corners produces directional scars. The lab uses wrap and records it in every receipt; a boundary mutant substitutes clamp so selected edge probes expose the change.
The finite-difference Laplacian is a numerical approximation whose visual character depends on spacing and weights. A four-neighbor stencil can emphasize axes. The nine-cell version reduces that obvious bias but does not make the simulation rotationally exact. The first figure keeps signed weights visible so the aesthetic consequence stays tied to code.
Do not hide the stencil behind a helper shared by candidate and oracle. The production update iterates offsets from a weight table. The reference update spells out nine indexed samples directly. If one weight changes, the two structures disagree at chosen asymmetric cells.
Double-buffer the Gray–Scott update
For each cell, compute uvv=U×V². Then update U with Du×laplacian(U)−uvv+F×(1−U), and V with Dv×laplacian(V)+uvv−(F+K)×V. Multiply both derivatives by the timestep and write into the next buffers. Swap buffers only after the entire grid is complete.
In-place updates are tempting because they halve visible storage, but later cells then read a mixture of old and new neighbors. The result depends on traversal order and no longer represents the stated explicit step. A named in-place mutant walks left to right and produces a distinct fingerprint after only a few updates.
Double buffering is also an artistic control. It makes a seed and parameter set replayable across runs in the same arithmetic environment, so palette and crop decisions can be compared against stable concentration fields. The receipt records typed-array precision and update order because changing either can alter late-stage pixels. In this reaction–diffusion Canvas study, buffer identity is part of the edition.
The method differs from diffusion-limited aggregation, where random walkers stick to a growing cluster. Here every cell evolves every step under coupled fields. Both reward deterministic seeds, but one replays stochastic paths and the other replays a discretized PDE.
Choose timestep and bounds for numerical legibility
An explicit update can become unstable when the timestep or diffusion coefficients are too large for the grid spacing. This study does not claim a universal stability theorem. It defines a conservative bounded parameter box, runs finite-value and concentration-range checks at checkpoints, and treats a failed check as an invalid edition rather than smoothing it away.
Clamping every value to [0,1] can keep pixels drawable while concealing divergence. If clamping is used, the receipt should count clamped cells and the validator should reconstruct that count. The default lab avoids clamping under its safe presets and rejects a timestep mutant that creates out-of-range values or a reference mismatch.
Visual legibility is separate from mathematical stability. A run can remain finite while collapsing into uniform gray, or generate beautiful spots while being sensitive to a tiny parameter change. The parameter atlas therefore reports summary statistics—minimum, maximum, mean, variance, and sampled residuals—beside each image. These are diagnostics for the Gray–Scott model, not aesthetic rankings or proof that browser-made Turing patterns reproduce nature.
With reaction–diffusion Canvas, the right default is a bounded composition that exposes failure. Keep a hard work cap at 64×64×1,200 updates, update progress without blocking keyboard controls, and allow reduced motion to disable animated stepping while preserving a single deterministic render.
One seed reveals a parameter neighborhood
A semantic atlas holds seed, time, diffusion, boundary, and palette constant while feed and kill values change.
| Study | Feed F | Kill K | Observed field | Variance |
|---|---|---|---|---|
| Coral split | 0.0367 | 0.0649 | dividing spots | 0.041 |
| Worm trail | 0.0300 | 0.0620 | connected bands | 0.036 |
| Open lace | 0.0260 | 0.0550 | wide negative space | 0.029 |
- Every row uses seed 2749, 64×64 cells, wrap, dt 1, and 900 steps.
- Only feed and kill differ between rows.
- Field labels are art-direction notes, not biological classifications.
- Variance is a diagnostic, not an aesthetic score.
Reading rule: headers, values, verdict words, and sequence carry the conclusion; color is supplementary.
Seed perturbations and make every run reproducible
The seed is both data and composition. Start U at one and V at zero, then place a small asymmetric cluster whose offsets come from a named integer PRNG. Asymmetry gives the stencil and boundary probes something meaningful to inspect; a perfectly centered square can let directional mistakes hide behind symmetry. Reaction–diffusion Canvas needs that seed identity to distinguish replay from resemblance.
Record the PRNG name, integer seed, placement rule, grid dimensions, and initial-state hash. “Seed 42” is incomplete if a later refactor changes the generator or consumes random values in a different order. The lab uses a tiny deterministic generator and generates the entire initial field from a versioned recipe before stepping.
Reproducibility has a boundary. JavaScript number operations are well specified enough for this bounded same-implementation reconstruction, but browsers can rasterize colors differently. The receipt binds the exact RGBA byte buffer and its hash; it does not promise cross-engine pixel identity. A validator recomputes the field and pixels in the current engine and compares both.
This separation resembles the choice in Worley noise texture systems: the mathematical field, sampling recipe, and art direction should have distinct identities. A saved image without its recipe is reference material, not a replayable edition.
Use Gray–Scott parameters as art direction
Feed F and kill K behave like a visual map. Nearby pairs can move from isolated spots to splitting coral, worms, sheets, or near-uniform fields. The parameter atlas holds seed, time, diffusion, boundary, resolution, and palette constant, changing only F and K. That turns a mood board into a controlled comparison.
Art direction continues after the solver. Map V, U−V, or another declared scalar to a palette with named stops. Choose a background, midtone, highlight, and contrast curve. Preserve the raw field hash separately so changing color does not masquerade as a different simulation. The article’s midnight coral-and-cyan treatment is one authored interpretation, not a canonical scientific visualization.
Alan Turing’s 1952 archive record for “The Chemical Basis of Morphogenesis” documents the paper’s foundational reaction-and-diffusion pattern idea. Pearson’s complex patterns in a simple system maps behavior in a Gray–Scott-style model. Those sources motivate the system; this browser artwork does not validate biology.
The MIT Gray–Scott reference offers a compact equation overview. Use it to check signs and terms, then keep the exact discretization, timestep, and boundaries of this implementation visible because those details control the pixels.
- Initial-state hash fixes the seeded perturbation.
- Selected U and V cells are checked at steps 1, 8, 64, and 900.
- Whole-field statistics and RGBA hash bind the final edition.
- Mutation fingerprints distinguish update, stencil, timestep, boundary, and identity failures.
Reading rule: labels, values, shapes, order, and line styles carry the conclusion; color is supplementary.
Verify steps, kill mutants, and bind pixels
Verification samples edge, corner, seed, and quiet cells at steps 1, 8, 64, and the final timestep. The production loop and direct reference stencil start from separately generated copies of the same canonical initial recipe. At checkpoints, the receipt records U, V, and absolute residual for every probe plus whole-field statistics.
Executable mutants cover in-place writes, wrong Laplacian weights, swapped feed and kill roles, excessive timestep, clamp instead of wrap, omitted seed identity, and a receipt whose raster hash is disconnected from pixels. Each mutant must violate a residual, range, identity, or reconstruction check. A static list saying “killed” is not evidence; the artifact runs every altered path.
The PNG export is paired with canonical JSON and CSV receipts. The canonical record binds width, height, species arrays by hash, F, K, Du, Dv, timestep, steps, boundary, PRNG, seed, palette stops, RGBA raster hash, probes, statistics, and mutation outcomes. JSON validation reparses and reconstructs. CSV carries the same canonical JSON and goes through the same path. This binding makes the reaction–diffusion Canvas image a reproducible generative texture rather than an unlabelled screenshot.
Coordinated tampering still fails. Changing the stored raster bytes and its claimed hash cannot change the raster rebuilt from the parameters. Changing parameters and outputs together fails the canonical input policy or reconstructed probes. This is the core evidence for reaction–diffusion Canvas, not a screenshot of a pleasing pattern.
Export the study without calling it biology
A responsible release names the work accurately: a deterministic numerical and artistic study of Gray–Scott equations. It does not claim chemical units, biological fidelity, universal stability, or identical pixels across engines. It also does not infer conservation in a system with feed and kill terms.
Keep the PNG next to its validated receipt and a readable parameter card. A gallery can cluster related parameter regimes, but every image should retain seed, timestep, step count, boundary, palette, and field identities. If the solver or palette changes, issue a new edition instead of silently refreshing the old one.
When choosing Canvas versus another renderer, use the same artistic target. The broader SVG versus Canvas generative-art comparison helps frame editability, mark count, accessibility, and export, while this study focuses on one pixel field. Canvas is appropriate here because every cell becomes a raster region; the semantic figure and receipt carry the meaning the pixels cannot.
The result should feel alive without borrowing authority from life science. The beauty comes from a precise feedback system, a controlled seed, and deliberate color—not from pretending the browser contains a petri dish.
Runnable local artifact — The work is a numerical and artistic Gray–Scott study, not evidence about living morphogenesis, chemical accuracy, physical units, universal stability, conservation, or cross-engine pixel identity.
Render a fixed 64×64 field in cooperative chunks; inspect precision, update order, parameters, checkpoints, statistics, raster identity, seven mutation fixtures, and PNG/JSON/CSV exports.