How it works
Two simulated chemicals react and diffuse on a grid of 2.5 px cells. This is the Gray-Scott model, and depending on two numbers it grows coral, worms, spots or mazes on its own. The trick is that those two numbers are not global. Your cursor paints a fading wake, and inside the wake the chemistry is set to a living pattern regime while everywhere else it is set to one where patterns die. So the pattern blooms out of spores a step behind you, holds for about four seconds, and then retreats by itself: fingers thin and withdraw, spots shrink, nothing fades to haze. Each frame the chemical is upsampled with a cubic B-spline and lit as glossy enamel or polished metal with a soft cast shadow, or drawn as constant-width neon contour lines. Around the cursor, and around any button it rests on, the pattern parts so it never covers what you are about to click.
Pipeline (per frame)
Sizes at 1280×720 CSS px, DPR 2 (a 2560×1440 canvas), cell 2.5 px, Steps 28.
load ─▶ PRE-ROLL: 30 hidden frames of the intro stroke (sim only, no display), so
the first visible frame already shows grown coral
pointer ─▶ ring of per-frame samples ─▶ PEN = where the pointer was 100 ms ago
│ (intro: no lag, 40 steps, spores ≥ .5, brush ×1.2)
│ live pointer: fluid splat, clear disc; hovered link/button: clear rect
│
├─▶ FLUID RG16F 228×128, velocity in texels/s (skipped 3 s after the last stroke)
│ grip splat (mix toward pointer velocity by 1 − e^(−21·dt))
│ ─▶ viscosity: 2 Jacobi, ν = 55 texel²/s ─▶ divergence
│ ─▶ 6 Jacobi (first warm-started from 0.8^(60·dt)·p) ─▶ v −= ∇p
│ ─▶ self-advect, fade 2/s
│
├─▶ MASK R16F 512×288 m = advect(m)·e^(−dt/τ) ; m = max(m, flat-top capsule at PEN)
│ capsule radius × lobes(cell) ∈ [.72, 1.28]: value noise, 20 cells, fixed
│
▼
RD STATE RG16F 512×288 ping-pong, stores (u = 1 − A, B), texelFetch, zero-flux edges
SEED advect by the fluid (once per frame, bilinear), then inside the PEN capsule
(same lobes): B = max(B, b·spore), u = max(u, .5·spore),
b = .3 + 6·max(0, F − .055); spores = 2-octave value noise at λ = 6 cells,
fixed in space (slow drift), threshold .72 − .3·Spores, lower toward the centre
STEP ×14 passes = 28 Gray-Scott steps (two per pass from a 5×5 neighbourhood)
9-point Laplacian, DA = 1, DB = .5, dt = 1
(F, k) = mix(dead, live, smoothstep(.30, .36, m)) ◀── the style map
live k = √F/2 − F + Kill offset
dead k = √F/2 − F + max(Kill offset, .011) + Dissolve
│
▼
PREP RGBA16F 512×288 (B, ∂B/∂x, ∂B/∂y, max B over 5×5) per cell
GLOW RGBA16F 256×144 ─▶ 128×72 ─▶ 64×36 (─▶ 32×18 on dark pages)
dual-filter down + tent up; rgb = glow (fill or edge band, × palette),
a = blurred coverage (the light page's shadow; on dark pages the 32×18
level's a is the density of shapes, which drives the gel)
│
▼
DISPLAY 2560×1440, premultiplied over the page (pointer-events: none)
4-tap cubic B-spline of PREP ─▶ clear windows (B pushed below iso)
edge: d = (B − .2)/|∇B| · px per cell ─▶ 1 px anti-aliased coverage
outside the live wake: coverage × smoothstep(.21, .245, peak)
dark page, inside a window: also × smoothstep(.21, .245, peak − push)
filled: dome height ─▶ normal ─▶ Blinn-Phong + glaze + ramp by thickness
metal: + sky gradient and a crisp reflection band (× window)
light page: rgb clamped to alpha, + cast shadow (B-spline of
GLOW.a, offset to the lower right)
dark page: + bloom (B-spline of GLOW.rgb), + gel when Glow > 1
(B-spline of the 32×18 level's a)
neon: 1–3 iso-lines at B = .20 / .11 / .30, Gaussian profile of fixed px
width, each drawn only where the peak clears its level by .012–.055;
the outer (.11) line also needs the peak to clear .21–.24
±1 LSB dither ─▶ canvas
35 passes per frame while you draw on a light page (37 on dark), 23 / 25 once the
fluid has settled; after the end-of-life fade, none
The ideas that matter
- Gray-Scott in one paragraph. Chemical A is fed into the grid at rate F. B turns A into more B (the term A·B²) and is removed at rate F + k. A diffuses twice as fast as B. That difference in diffusion is what lets B form stable shapes of a fixed size instead of spreading evenly: Turing's mechanism. Feature size is measured in grid cells, about 8–12 cells for these regimes. That is why the cell size is fixed in CSS pixels. If the grid were sized from device pixels, coral would be half as big on a Retina screen.
- Pearson's classification, and how the Pattern menu and the Kill slider use it. In 1993 John Pearson swept the (F, k) plane from a single seed and labelled the behaviours with Greek letters α to μ. Robert Munafo later extended the atlas (ν, ξ, π and more). Everything interesting sits on a thin crescent just above the saddle-node line k = √F/2 − F. Below that line a uniform B-rich state can exist, and patterns fatten, merge and fill space. Just above it only isolated structures survive: stripes, then worms, then spots and solitons. A little further up, everything decays to plain A. So the
Kill offsetslider is measured from that line rather than being a raw k. A raw k slider over Sims' whole map was mostly dead or solid, and the class flipped within a pixel of travel. Measured on this page with its seeds: below 0 the shapes fatten and merge, and by −0.003 the wake fills solid. From 0 to about +0.002 every feed in the range grows a connected pattern. Above that only spots and arcs survive, and how far up depends on the feed: at F ≤ .035 they still grow at +0.007, at F = .065 only a sparse scatter does, and at F = .08 nothing survives past about +0.004. Feed stops at .08 for the same reason. At .09 the best offset grew two dots, and at .10 nothing at all. Its slider is logarithmic because most of the classes sit between .01 and .06. The menu picks points on the crescent (raw values, then their offset):Coral(F .0545, k .062, −.0002) is Karl Sims' “coral growth”, in Pearson's κ territory of long branching stripes;Worms(.050, .063, +.0012) is Munafo's example of κ itself: long, convoluted, mostly connected worms;Spots(.030, .062, +.0054) is pmneila's “Solitons”, on the λ side of the map;Mitosis(.0367, .0649, +.0058) is Sims' mitosis, Pearson's λ, where spots grow and split like cells;Labyrinth(.029, .057, +.0009) is pmneila's “Mazes”, next to Pearson's θ, where rings merge into stripe networks. A change of 0.001 in k can still flip the class, which is why the slider shows four decimals. - The style map is the whole effect. Patterns fill the screen and never stop on their own. So F and k vary per cell, after Sims' “style map”. Inside the wake mask they take the live regime; outside it, a dead one. A pattern then retreats the way it grew, by its own chemistry, instead of being faded out with alpha.
- Three measured lessons about the dead regime. First, any live-to-dead blend sweeps a cell through the intermediate regimes, and coral passing through the spot classes breaks into beads. A soft blend (mask .42 → .28) left long dotted trails. The switch is now sharp (mask .36 → .30, about 0.7 s at τ = 4). That reduces the bead stage rather than skipping it: most fingers thin and withdraw, but the oldest tail still breaks into a short run of beads before it goes. Second, “dead” has to mean dead for every F. With k only 0.006 past the crescent line, λ-class solitons survived outside the wake and slowly spread. They would eventually have filled the page. So dead k is at least 0.011 past the line, plus
Dissolve, plus another 0.01 once the page winds down. Third, the last moments of a dying spot looked like dull grey-green dust: it was too thin to light or glow. So outside the live wake, a shape whose local peak of B (a 5×5 max stored in PREP) is within 0.045 of the edge level fades out. Inside the wake young spores are left alone; they dip in B before they grow. - The fp16 trick: store 1 − A, not A. Half floats have 10 mantissa bits, so just below 1.0 consecutive values are 2⁻¹¹ ≈ 0.00049 apart. Away from the pattern A sits near 1, and the per-step feed F·(1 − A) is far smaller than that gap, so it rounds away. A stalls, and patterns stop forming or drift. Near 0 the same format resolves steps of about 10⁻⁶. Storing u = 1 − A puts the background where fp16 is dense: the update is just u += ∇²u + A·B² − F·u, done in fp32 in the shader. The state then fits in an RG16F texture, which is renderable, filterable and half the bandwidth of fp32, on every GPU this page runs on.
- Spores at the pattern's own wavelength. The trivial state (A = 1, B = 0) is stable, so nothing grows without a seed, and some classes need a large one. The stroke stamps blobs of two-octave value noise, about 6 cells across. They give the reaction the right scale to start from, so coral differentiates within ~300 ms of a stroke. The threshold is 0.07 lower in the middle of the stroke than at its edge, so the core starts as a tangle. High feed makes the empty state more stable, so the high-F classes (Munafo's ν and π) need a bigger kick: the seed's B rises from 0.3 at F = .055 to 0.45 at F = .08. Without it, F = .08 grew only a few dots. The noise is fixed in space (it drifts slowly), so overlapping capsules from consecutive frames re-stamp the same spores (max is idempotent). Fast and slow strokes therefore seed alike, with no per-distance normalisation.
Sporesmoves the noise threshold: 0 gives an airy wake of rings and loose coral, 1 a packed band. More is not always more: dense seeds starve the spot regimes of A, and a Mitosis band seeded at 0.85 came out sparser than one seeded at the default. Mitosis gets its density from running 32 steps a frame instead. - Growth starts behind you. The wake is not stamped under the pointer but where it was 100 ms ago, read by interpolating a ring of per-frame samples (in shell time, so the reduced-motion still lags the same way). A new stroke clears the ring, so nothing is ever drawn across a jump. Combined with the clear window, the visible coral begins about a brush width behind the cursor. The intro's ghost stroke has no cursor to stay behind, so it skips the lag.
- A lobed wake, not a tube. A Turing pattern lines up along a wall. In a straight-walled band, one stroke grew two or three rails parallel to the edges, joined by sparse rungs: a ladder. Real branching coral only appeared where strokes overlapped. Now the brush radius is multiplied by a slow value noise fixed on the grid (about 20 cells across, ×0.72 to ×1.28), in both the mask and the seed. The live region gets bulges and bays, and the stripes have no straight wall to align with. With a wider default brush (0.14 screen heights) and more spores (0.45), a single 1 s stroke now grows branching coral and a maze across the whole band.
- A pre-rolled intro. Coral needs a few hundred reaction steps before it reads as coral, so the intro used to open on an empty page with two specks. Now, before the loop starts, the first second of the ghost stroke is simulated off-screen in 30 frames. The path runs at twice its speed, and only the simulation passes run, as the reduced-motion still does for its whole stroke. During the intro the pen also has no lag, runs 40 steps a frame, plants spores at 0.5 or more and uses a 1.2× brush. So the first visible frame already shows a grown patch at the right edge, and the 3.5 s stroke then crosses the stage in a slow S. On a portrait screen the path becomes a vertical S down the whole height, and the brush narrows with √aspect so one stroke does not cover the whole width. Once the shaders are cached it costs almost nothing on the CPU: in one browser session, after the first (cold) load, the load event fired at 46–49 ms with the pre-roll and at 42–46 ms without it.
- Two steps per pass. Each STEP pass reads a 5×5 neighbourhood, computes the 3×3 intermediate states and then the final one, so 28 steps cost 14 passes instead of 28. On a tiled GPU the fixed cost of each pass dominates a 147k-cell grid, so this is worth more than the extra arithmetic costs.
- Lit at full resolution from a 1/5-res field. One prep pass stores B, its gradient and its local peak per cell. The display fetches them through a 4-tap cubic B-spline, which is C²-smooth, so there are no bilinear diamonds or stair-steps after the 5× upsample. The edge is drawn by distance, (B − iso)/|∇B| converted to pixels, which gives a 1 px anti-aliased rim and constant-width neon lines however the pattern stretches. Height is a dome, h = 1 − (1 − x)², x = (B − iso)/0.2, so the surface is steep at the rim and rounded on top. A thickness ramp (pale at the thin rim, deep at the core) plus Blinn-Phong and a broad “window” reflection make the enamel. On a light page the colour is clamped to 1 before it is multiplied by coverage. Specular and window terms above 1 used to make rgb exceed alpha at anti-aliased rim pixels, an invalid premultiplied value that showed as a 1 px white fringe.
Specularscales the gloss as s·(1 + s)/2, so the range runs from matte bisque at 0 through glazed enamel at 1 to a wet clear coat at 2.5. Gold is shaded as a metal: the normal looks up a sky gradient (dark ground, bright sky toward the upper left) tinted by the gold, plus a crisp bright band that slides over the shoulders facing the light. That band is what makes it read as polished rather than satin. - Neon lines that never dash. The innermost iso-line (B = .30) sits close to the plateau of a maze stripe, so it used to break into white dashes and pills that popped in and out. Each line is now drawn only where the local peak of B clears its level by 0.012–0.055. The outer line (B = .11) also needs the peak to clear the main line's level (0.21–0.24). Where B plateaus between .11 and .20, on thin, young or dying stripes, it used to draw a lone violet contour with no cyan partner, which wandered across the headline. The default is two lines per edge at 2.2 CSS px, on 3 px cells for more negative space. On a light page the lines switch to the palette's deep colours and are drawn 1.2× heavier, so they read on cream.
- Shadow and bloom from one pyramid. The glow source stores colour in RGB and coverage in alpha. A dual-filter pyramid blurs both. Light pages read the first three levels' alpha, offset toward the light, as a soft cast shadow tinted with the palette's shadow colour;
Glow / shadowsets its strength. That read has to be a B-spline too: a plain bilinear tap of the 1/10-res pyramid showed visible stair-steps along the shadow edge. Dark pages add the RGB as bloom, with a fourth, 1/16-res level weighted more heavily (each up-step mixes 70 % of the coarser level instead of 55 %). The halo alone did not make Mitosis read as one trail: the cells still looked like polka dots with a faint glow. So when Glow is above 1, the alpha of that 1/16-res level (the density of shapes over about 16 cells), read through the B-spline, fills the wake between the shapes with a translucent gel in the glow colour, at most 22 % of it. It is a smoothstep of a density rather than a blur of the colour, so it has an edge and leaves no haze outside the wake. - Clear windows that part the pattern. Fading alpha near the pointer left a ghostly half-transparent coral. Instead, B is pushed below the iso level, so edges and neon lines bend away and stay crisp. There are two windows. One is a disc around the pointer, fully clear inside 0.5 brush radii and back to normal at 1.3. The other is a rounded rect around the link or button the pointer is over, which stays open for 0.5 s after the pointer leaves. Both ease in and out with a 0.12 s time constant. The gradient correction comes from central differences of the window one cell apart. The glow source applies the same windows, so the bloom does not leave a smudge where lines were removed. The display then adds the blurred bloom as it is. Multiplying it by the window a second time cut a crisp dark disc out of the halo, which followed the cursor and bent the neon lines into a cookie-cutter circle. On light pages the peak cull ignores the windows: a parted shape should shrink, not turn translucent. On dark pages a parted Mitosis cell shrank into a dull olive pebble, too thin to light and with its glow cut away. So there the cull also runs on the peak as lowered by the window, and the colour ramp reads the thickness from before the window: a parted shape keeps its colour while it shrinks and fades. Gold's reflection band and highlights are scaled by the window too, so the tips of parted shards do not glint.
- Flow, gently. A small viscous stable-fluids solver advects the chemical and the mask once per frame, before the reaction steps. Semi-Lagrangian advection blurs, but the reaction re-sharpens fronts within a few steps. The fluid converges to the pointer's velocity under the brush. So a gain of 1 would carry the chemicals along with the cursor, and the old maximum of 1.5 slid the whole wake to the end of the stroke and piled it at the screen edge.
Flownow stops at 0.8, and the fluid fades at 2/s, so the drag shows while you move and stops soon after. The default 0.3 is a drag you feel more than see. 0.8 combs coral into long parallel rails. The grip toward the pointer's velocity is a rate, 1 − e^(−21·dt), which is 0.3 at 60 Hz. The pressure solve's warm start keeps 0.8^(60·dt) of last frame's field. So at 120 Hz the fluid does not lock onto the pointer faster. - An end that follows Wake decay. Each cell dies on its own when its mask drops through .36–.30, about 1.1·τ after it was painted. The global end of life is derived from the same τ. At 1.1·τ + 0.5 s after the last input the whole field switches to the dead regime over 1 s and retreats. An alpha fade runs 2.1–3.0 s after that, and the loop stops at 1.1·τ + 3.8 s, which is 8.2 s at the default τ = 4. The shell's idle timeout is fixed when the page starts, so the shell gets the shortest life (4.5 s) and the frame keeps it awake with
fx.wake()until the decay-derived end. Once the fade completes, the state is wiped, so a later stroke starts clean, and the remaining frames skip all GPU work. - No flash on load. The page is light by default, but the shared shell boots dark, and its theme switch flushes styles before the preset applies, so the background used to cross-fade from black to cream over half a second. The page now boots light (an effect-side
--bgfor the light theme), and the theme transitions are suppressed until two frames after start. A dark?preset=therefore also switches instantly.
Parameters
Presets
Performance & compatibility
- All numbers are from 31 October 2026: an Apple M5 (base, 10-core GPU), headless Chrome driven by the library harness or by a probe that replays its sweep (a fresh page, 1 s after load, the 1.5 s lemniscate), at a 2560×1440 canvas. This GPU is shared with other agents' runs, and with no code change its timer numbers swung by 2× between back-to-back sessions. So each comparison below comes from one session with the configurations interleaved, and every absolute value is an upper bound.
- Per preset, from one session (03:44) that started after 20 s with no other harness or probe process and had none during it. Six rotated repetitions, about 600 frames each; GPU ms per frame, mean / median / p95: Coral (default) 7.2 / 6.4 / 14.4, Labyrinth 7.2 / 6.2 / 16.5, Mitosis 7.7 / 7.0 / 14.0, Gold relief 7.6 / 6.9 / 14.7. JS stays near 0.1 ms. In the same session the previous Mitosis (2 px cells, 40 steps, 43 passes) measured 10.2 / 8.4 / 23.2. It now uses 2.5 px cells and 32 steps, 39 passes and about half the reaction work.
- The default against the previous version of this page, one session, eight interleaved repetitions (about 800 frames each): 6.8 / 6.0 / 12.6 ms now, 7.0 / 6.1 / 13.6 ms before. The wider brush, the lobed outline and the denser spores cost nothing measurable. Harness runs of this code the same night measured 7.6 to 16.2 ms mean and 14.0 to 44 ms p95, depending on how many other runs shared the GPU. The last full run (03:48, no other harness run active as it started) measured 8.4 / 14.0 ms mean / p95 GPU, 0.1 ms JS, 60 fps.
- Cost breakdown, measured on the previous version, whose pass structure is unchanged: an A/B in one session, five interleaved repetitions, GPU ms p10 / median: default 3.9 / 7.8;
Flow0 4.0 / 7.5;Steps2 +Flow0 1.2 / 2.8. So the fluid's 12 small passes are within the noise, well under 0.5 ms. The reaction steps are most of the frame: 26 fewer steps (13 fewer passes) save 2.7 ms at p10 and 5 ms at the median. Contention inflates many-pass work most, because every pass waits its turn on the shared GPU. - Cost is mostly pass count and the full-resolution display.
Steps / frame(one pass per two steps) is the main knob.Cell sizescales the cost of each pass: 2 px cells mean 1.56× the cells of 2.5 px. SettingFlowto 0 drops the fluid entirely. The display pass exits after two texture taps on empty page pixels; the gel adds four taps on dark filled pages only. After the end-of-life fade no GPU work is issued at all. Textures take about 4.3 MB at the default 2.5 px cell (Mitosis included) and about 6.3 MB at 2 px. The pre-roll costs 30 frames of simulation passes once, before the first frame. - Needs WebGL2 with
EXT_color_buffer_float(R16F, RG16F and RGBA16F render targets). Thanks to the 1 − A trick nothing needs fp32. Without them the library's fallback card appears over the live, clickable hero, with a static coral band drawn behind the hero by SVG filters: iso-bands offeTurbulencenoise inside a blurred stroke along the intro path, then embossed with diffuse and specular lighting and coloured by a ramp from the blurred thickness (pale rim, salmon body, crimson in the thick cores). It makes no network request. - Phones: at 390×844 with touch (DPR 3, capped at 2) the canvas is 780×1688 and the reaction grid 156×338. Cells stay 2.5 CSS px, so coral has the same physical size as on desktop. On a portrait screen the brush narrows with √aspect (0.68× at this size), and the intro draws a vertical S down the whole height. The harness measured 53.4 fps for a touch drag (headless Chrome on the Mac, not a real phone). The controls become a bottom sheet.
- The gallery thumbnail (
?embed, DPR 1) scales the cell with the stage height but keeps at most 160 rows, runs at most 16 steps a frame, scales the neon line width with the cell and widens the brush 1.3×. At the harness's 640×400 that is a 256×160 grid, instead of the 461×288 (the full page's RD cost) it used to be. The gallery runs several live thumbnails at once. In one session, interleaved, the thumbnail's GPU time fell from 11.7 to 4.3 ms mean for Coral and from 7.9 to 4.6 ms for Labyrinth. These absolute numbers are inflated: at this light load the GPU does not clock up, so read them as a ratio. - With
prefers-reduced-motionthe intro stroke is simulated off-screen for 170 frames (about 6,800 reaction steps at the intro's 40 a frame) and shown as one still, with a “Play anyway” button.
References & credits
- P. Gray & S. K. Scott, “Autocatalytic reactions in the isothermal, continuous stirred tank reactor: isolas and other forms of multistability”, Chemical Engineering Science 38(1), 29–43 (1983): doi:10.1016/0009-2509(83)80132-8; and “… oscillations and instabilities in the system A + 2B → 3B; B → C”, Chem. Eng. Sci. 39(6), 1087–1097 (1984): doi:10.1016/0009-2509(84)87017-7 (papers). The model.
- J. E. Pearson, “Complex Patterns in a Simple System”, Science 261 (1993): arxiv.org/abs/patt-sol/9304003 (paper), the classification.
- R. Munafo, Xmorphia and the extended Pearson classes: mrob.com/pub/comp/xmorphia (article).
- Karl Sims, “Reaction-Diffusion Tutorial”: karlsims.com/rd.html (© Karl Sims, article). The 9-point kernel, DA = 1, DB = .5, dt = 1, the coral and mitosis (F, k), and the style-map, flow and embossed-lighting ideas.
- pmneila/jsexp Gray-Scott: github.com/pmneila/jsexp (BSD-3-Clause). The (F, k) values for “Mazes” and “Solitons” only, no code.
- Linus Mossberg, reaction-diffusion: github.com/linusmossberg/reaction-diffusion (MIT). A Phong-lit RD height field; studied, no code copied.
- C. Sigg & M. Hadwiger, “Fast Third-Order Texture Filtering”, GPU Gems 2 ch. 20: developer.nvidia.com (book text). The 4-tap B-spline.
- J. Stam, “Stable Fluids” (SIGGRAPH 1999), and M. Harris, “Fast Fluid Dynamics Simulation on the GPU”, GPU Gems ch. 38: developer.nvidia.com (book text).
- M. Bjørge (Arm), “Bandwidth-Efficient Rendering”, SIGGRAPH 2015 Moving Mobile Graphics course: slides (PDF, community.arm.com) (talk slides, © Arm). The dual-filter blur.
- Dave Hoskins, “Hash without Sine”: shadertoy.com/view/4djSRW (MIT). The
hash3function is adapted from it, with attribution in the source. - W3C, Filter Effects Module Level 1 (
feTurbulence,feComponentTransfer, lighting primitives): w3.org/TR/filter-effects-1 (W3C document licence). Used only for the static no-WebGL2 motif. - This library's research notes (
research/rd-metaballs-sdf.md), which suggested the lagged seed, and its reference fluid trail, which supplied grip, capsule splats and implicit viscosity. Everything else on this page is written from scratch.