Task 3 of 4
One step is chemistry; a hundred steps is morphogenesis. The kernels stay on the GPU — the loop lives in JavaScript: call both step kernels, take their outputs, feed them back in as next step's inputs. This is the same feedback move as the cellular automata in 3.3, just with two grids in flight instead of one.
The trap: both kernels must read the same snapshot. If you
overwrite u before calling stepV, chemical V reacts with food
from the future — the simulation drifts and the tests will know. Hold both new
grids, then swap. Graphics folk call this ping-pong buffering.
seedU / seedV, feeding each step's outputs into the next —
both kernels always reading the same snapshot.STEPS (100) times in plain JavaScriptawait stepU(u, v) and await stepV(u, v) with the same u and vu and v with the new gridsThe starter does
u = await stepU(u, v);
v = await stepV(u, v);
— by the
second call, u is already next step's grid. Stash both results in
temporaries before assigning either.
const nextU = await stepU(u, v);
const nextV = await stepV(u, v);
u = nextU;
v = nextV;
Four lines, inside
for (let i = 0; i < STEPS; i++).
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.