oneshotlm
Compare all models on this prompt →

Reaction-diffusion · grok-build-0.1

Run a Gray-Scott reaction-diffusion simulation on a canvas that grows organic Turing patterns in real time, with the mouse seeding new growth.

⛨ sandboxed Open in new tab ↗
transcript · 6 messages
user

Run a Gray-Scott reaction-diffusion simulation on a canvas that grows organic Turing patterns in real time, with the mouse seeding new growth.

assistant
thinking
The user wants a single-page web app in one self-contained index.html file. It must include:
The task is to create a single-page web app in one index.html file that runs a Gray-Scott reaction-diffusion simulation with Turing patterns growing organically in real time, seeded by mouse movement. It must be self-contained with CSS in <style> and JS in <script>, no external resources.

I need to implement the 2D Gray-Scott model using HTML5 canvas and JavaScript.

Key components:

1. **HTML Structure:**

   - <!DOCTYPE html>

   - <html>

   - <head> with <style> for canvas styling (full-screen, etc.)

   - <body> with <canvas id="canvas"></ canvas>

   - <script> for the simulation code

2. **Simulation Parameters:**

   - Use standard Gray-Scott parameters: Du ≈ 0.16, Dv ≈ 0.08, F ≈ 0.035, k ≈ 0.065 for spots.

   - Allow for mouse seeding: when mouse moves, add V=1 in a small area around mouse position.

3. **Simulation Grid:**

   - Use a 256x256 grid for efficiency.

   - Canvas size: 512x512 to scale up nicely.

4. **Update Loop:**

   - Use requestAnimationFrame for animation.

   - Run multiple iterations per frame (e.g., 10) for smoothness.

5. **Laplacian Calculation:**

   - Use 5-point stencil: center + up, down, left, right.

6. **Mouse Interaction:**

   - Capture mousedown/mousemove events.

   - Set V high in a 5x5 or radius area around mouse.

7. **Rendering:**

   - Use ImageData for fast pixel updates.

   - Color map: e.g., grayscale based on V or a nice organic palette (blues, greens, purples).

8. **Initialization:**

   - Fill U=1, V= 0.

   - Add initial random seeds for patterns to start.

9. **Controls:**

   - Simple buttons for presets (spots, stripes) by changing F,k.

   - Sliders for F, k, etc.

   - Pause/resume.

Since it must be self-contained and one file, include all in 1 HTML.

Confidence: I know Gray-Scott well, have implemented similar. Code will be ~200-300 lines JS. \confidence{70}

Final answer is the index.html code. But since long, I need to write it. 

The response should be the HTML code as answer.

But the instruction: report confidence inside \confidence{}.

So, I need to output the HTML, then \confidence{xx}

Let's construct the code. 

First, sketch code. 

<html>
<head>
<style>
body { margin:0; overflow:hidden; background:black; }
canvas { display:block; }
#controls { position:absolute top:10px left:10px; background:rgba(0,0,0,0.5); padding:10px; color:white; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="controls">
<button id="spots">Spots</button>
<button id ="stripes">Stripes</button>
<button id="reset">Reset</button>
<button id="pause">Pause</button>
F: <input type="range" id="f" min="0.01" max="0.1" step="0.001" value="0.0545">
 <span id="fval">0.0545</span><br>
k: <input type="range" id="k" min="0.01" max="0.1" step="0.001" value="0.062">
  <span id="kval">0.062</ span>
</div>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
canvas.width = 512;
canvas.height = 512;
const W = 256;
const H = 256;
const scale = 2;
const u = new Float32 Array(W*H);
const v = new Float32Array(W*H);
const u2 = new Float32Array(W*H);
const v2 = new Float32Array(W*H);
const Du = 0.16;
const Dv = 0.08;
let F = 0.0545 ;
let k = 0.062;
let dt = 1;
let steps = 10;
let paused = false;
let mouseDown = false;
let brushR = 5;
let mouseX = 0, mouseY = 0;
function getIdx(x,y) { return ((x%W +W)%W) + ((y%H +H)%H)*W; }
function init() {
  for(let i=0; i<W*H; i++) {
    u[i] = 1;
    v[i] = 0;
  }
  seed();
}
function seed() {
  for(let s=0;s<10;s++) {
     let cx = Math.floor(Math.random()*W);
     let cy = Math.floor(Math.random()*H);
     for(let dy=-3;dy<=3;dy++) for(let dx=-3;dx<=3;dx++) {
       let x = ( cx+dx +W)%W;
       let y = (cy+dy +H)%H;
       let i = getIdx(x,y);
       v[i] = 1;
       u[i] = 0.4;
     }
  }
}
function applyBrush(x,y) {
  for(let dy = -brushR;dy<=brushR;dy++) {
    for(let dx=-brushR;dx<=brushR;dx++) {
      if(dx*dx+dy*dy > brushR*brushR) continue;
      let nx = (x+dx +W)%W;
      let ny = (y+dy +H)%H;
      let i = getIdx(nx,ny);
      v[i] = 1;
      u[i] = 0.
write /tmp/ws/index.html (13508 bytes)
toolResult

Successfully wrote 13508 bytes to /tmp/ws/index.html

assistant
thinking
The file has been created. Now I need to verify that it runs properly. I should check if index.html is present and perhaps test it somehow, but since it's a web app, I can't really run it in a browser...
bash {"command":"ls -la /tmp/ws/index.html && wc -c /tmp/ws/index.html"}
toolResult

-rw-r--r--. 1 node node 13512 Aug 1 20:39 /tmp/ws/index.html 13512 /tmp/ws/index.html

assistant
thinking
The file has been created successfully. It's a fully self-contained single-file Gray-Scott reaction-diffusion simulation with:

Done. Created `/tmp/ws/index.html` — a fully self-contained Gray-Scott reaction-diffusion simulator. **Features:** - Real-time simulation on a 256×256 grid (rendered at 2× on a 512px canvas) - Classic Turing pattern emergence (spots, worms, labyrinths, etc.) - Click & drag to seed new activator (V) growth — instantly spawns patterns - 5 presets: Spots, Worms, Labyrinth, Chaos, Holes - Live sliders for F, k, simulation speed, and brush radius - Pause / Clear / Random Seeds / Reset controls - Touch support - No external resources — 100% offline and sandboxed Open `index.html` in any browser to watch the patterns evolve. The mouse is the best way to interact and explore different regions.

TAKE IT TO CODE

A single self-contained HTML file — copy it and open in any browser, or reuse the prompt with your own pi-agent run.

RUN

modelgrok-build-0.1
vendorxAI · Grok
harnesspi-agent
generated2026-08-01

EVALUATION

4/5 working

Gray-Scott reaction-diffusion evolves organically and responds to click/drag seeding; keyboard has little effect but wasn't the main interaction.

Vision grade · anthropic/claude-sonnet-5

MEASUREMENTS

Raw readings from the capture, not a verdict — the grade above is the only judgement. Percentages are how much of the screen changed; the measure under-reports sparse motion on a dark background.

idle motion3.9%
on click15.3%
on drag13.4%
on wheel3.6%
on enter + space27.9%
on arrow keys0.7%
on w/a/s/d0.4%
frame spread79.9 / 255
console errors0
js errors none

METRICS

runtime78.0s
tokens in4.5k
tokens out12k
cached8.9k
cost / run$0.0302