oneshotlm
Compare all models on this prompt →

Mandelbrot explorer · gemma-4-26b-a4b-it

Render the Mandelbrot set with a smooth color gradient on a full-screen canvas, with click-and-drag to pan and mouse-wheel to zoom.

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

Render the Mandelbrot set with a smooth color gradient on a full-screen canvas, with click-and-drag to pan and mouse-wheel to zoom.

assistant
thinking
The user wants a single-file web app (`index.html`) that renders the Mandelbrot set.
Key requirements:
1.  Single file: `index.html` containing HTML, CSS, and JS.
2.  Smooth color gradient.
3.  Full-screen canvas.
4.  Interaction:
    *   Click-and-drag to pan.
    *   Mouse-wheel to zoom.
5.  No external resources (no CDNs, no network requests).

Plan:
1.  Create an `index.html` file.
2.  Structure:
    *   `<canvas>` element covering the whole screen.
    *   CSS to make the canvas full-screen and remove margins/overflow.
    *   JavaScript to handle:
        *   Canvas setup and resizing.
        *   Mandelbrot calculation (optimized with Web Workers? Or just a single-threaded loop for simplicity if it's fast enough, but for a "smooth" experience, maybe Web Workers or at least `requestAnimationFrame` with tiling/chunking). Actually, since it's a single file, I can embed the Worker code as a Blob.
        *   Zooming and panning logic.
        *   Coloring (smooth coloring algorithm).

Smooth coloring formula:
$v = n + 1 - \log_2(\log_2(|z|))$
where $n$ is the iteration count where $|z| > 2$.

Optimization:
*   Use `ImageData` to manipulate pixels.
*   Use `requestAnimationFrame` for smooth updates.
*   To keep it responsive during zoom/pan, I might need to use a lower resolution during interaction or a worker. Since it's a single file, a Web Worker created from a `Blob` is the best way to avoid freezing the UI.

Let's refine the implementation details.

Web Worker approach:
*   Main thread handles UI, input, and rendering the result.
*   Worker thread handles the heavy computation.
*   The worker will receive parameters: width, height, view window (xmin, xmax, ymin, ymax), and max iterations.
*   The worker will return the pixel data.

Interaction logic:
*   `mousedown`: start panning.
*   `mousemove`: update panning offset if dragging.
*   `mouseup`: end panning.
*   `wheel`: calculate zoom factor and adjust view window.

View window:
*   `centerX`, `centerY`, `zoom` (or `width_in_complex_plane`).
*   `xmin = centerX - width/2`
*   `xmax = centerX + width/2`
*   `ymin = centerY - height/2`
*   `ymax = centerY + height/2`
*   Wait, it's easier to use `centerX`, `centerY`, and `range` (where range is the width in the complex plane).
*   `aspectRatio = canvasWidth / canvasHeight`
*   `width = range`
*   `height = range / aspectRatio`
*   `xmin = centerX - width / 2`
*   `xmax = centerX + width / 2`
*   `ymin = centerY - height / 2`
*   `ymax = centerY + height / 2`

Smooth coloring:
Instead of just `n`, we use the fractional part.
For each pixel:
1. $z_{n+1} = z_n^2 + c$
2. If $|z_n| > R$ (where $R$ is large, e.g., 100), stop.
3. $n$ is the iteration count.
4. $\nu = n + 1 - \log_2(\log_2(|z_n|))$
5. Map $\nu$ to a color.

Let's start writing the code.
write index.html (8020 bytes)
toolResult

Successfully wrote 8020 bytes to index.html

assistant

The Mandelbrot set explorer is now implemented in `index.html`. It features: * **Full-screen rendering**: Uses a `<canvas>` that fills the window. * **Smooth Coloring**: Implements the renormalization formula ($n + 1 - \log_2(\log_2(|z|))$) to create smooth color transitions instead of discrete bands. * **High Performance**: Uses a Web Worker to perform the heavy fractal calculations in a background thread, preventing the UI from freezing during renders. * **Interactive Navigation**: * **Pan**: Click and drag the mouse to move around the complex plane. * **Zoom**: Use the mouse wheel to zoom in and out. The zoom is centered on the mouse cursor for intuitive exploration. * **Dynamic Iterations**: Automatically scales the maximum number of iterations as you zoom in to maintain detail. * **Self-contained**: All HTML, CSS, and JavaScript (including the worker script) are contained within a single `index.html` file. To view the app, simply open `index.html` in any modern web browser.

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

modelgemma-4-26b-a4b-it
vendorGoogle
harnesspi-agent
generated2026-07-22

EVALUATION

4/5 working

Mandelbrot set with smooth psychedelic gradient; drag pans and wheel zooms correctly, click/arrows/wasd had no effect.

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 motion0.0%
on click0.0%
on drag38.5%
on wheel31.2%
on enter + space24.6%
on arrow keys0.0%
on w/a/s/d0.0%
frame spread73.1 / 255
console errors0
js errors none

METRICS

runtime86.9s
tokens in4.9k
tokens out3.2k
cached0
cost / run$0.0014