Task 2 of 4

One Step of Gray–Scott

Now the chemistry. Gray–Scott tracks two chemicals on the same grid: U (food, fed in everywhere) and V (the eater — U + 2V → 3V, so V converts U into more V, and is itself slowly removed). Per cell, per step:

u' = u + (Du·∇²u − u·v² + F·(1 − u))·dt
v' = v + (Dv·∇²v + u·v² − (F + K)·v)·dt

Each equation is your task-1 Laplacian plus three pointwise terms — diffusion, reaction, feed/kill. One kernel per chemical: both are gathers over the old grids, so all 1,024 cells of a step can run in parallel.

one snapshot in, two grids out — u·v² is where the chemistry happens
Goal: finish the two update kernels — stepU and stepV each return their chemical's next value. The Laplacians are already gathered for you.

Requirements

Hint 1 — everything is already in scope

lap, uc and vc are computed for you; the parameters live in this.constants (du, f, dt in stepU; dv, f, k, dt in stepV). The TODO is one return per kernel.

Hint 2 — stepU, spelled out
return uc + (this.constants.du * lap - uc * vc * vc
  + this.constants.f * (1 - uc)) * this.constants.dt;

stepV is the same shape with + uc·vc·vc and − (f + k)·vc.

Same idea elsewhere

Fusing the stencil and the pointwise chemistry into one kernel is a classic GPU move — in CUDA or a WGSL compute shader you'd do exactly this to touch each grid cell's memory once per step instead of once per term. Separate passes per term would triple the bandwidth bill.

All tasks in Reaction–Diffusion

  1. The Laplacian: Ask Your Neighbors
  2. One Step of Gray–Scott
  3. Feed It Back: 100 Steps
  4. Paint the Pattern

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.