oneshotlm
Compare all models on this prompt →

Double pendulum · grok-build-0.1

Simulate a chaotic double pendulum on a canvas using the correct equations of motion, drawing the arms and a colorful fading trail of the tip.

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

Simulate a chaotic double pendulum on a canvas using the correct equations of motion, drawing the arms and a colorful fading trail of the tip.

assistant
thinking
The task is: "Build a single-page web app and write it ALL into one self-contained file named index.html in the current directory: CSS in a <style> tag, JS in a <script> tag, inline — do not create se...First, the task is to build a single-page web app in index.html that simulates a chaotic double pendulum on a canvas, with arms drawn and a colorful fading trail of the tip. Everything in one file: CSS in <style>, JS in <script>, no externals.

It must run fully sandboxed, no network.

I need to use correct equations of motion.

I'll implement a double pendulum simulation using numerical integration (Euler method for simplicity, or RK4 if possible).

Parameters: masses m1,m2, lengths l1,l2, gravity g, initial angles.

For trail: colorful fading – probably particles or lines with color changing over time, fading alpha.

Draw arms: lines from pivot to joint to tip.

Canvas: full screen or large.

Controls: buttons for start/pause/reset, sliders for params.

Confidence: I know double pendulum basics, equations are standard, trail common. \confidence{70}

Now, write the code in 1 file.

Structure:

<!DOCTYPE html>

<html>

<head>

<title>Chaotic Double Pendulum</title>

<style> /* CSS for canvas, controls */ </style>

</head>

<body>

<canvas id="canvas"></canvas>

<div id="controls"> /* sliders, buttons */ </div>

<script> /* JS code: vars, init, loop with RAF, physics func */ </script>

</body>

</html>

In JS:

- Get canvas, ctx = canvas.getContext('2d')

- Resize canvas to window size.

- Define params: let m1=1, m2=1, l1= 200, l2=200, g=9.81 etc.

- theta1=0.1, theta2=0.2 rad initial

- omega1=0, omega2=0

- dt = 0.01

- isRunning = true

- trail: array of {x,y , hue}

- function update() { if running, compute acc, integrate state, add tip to trail, shift if too long }

- function draw() { clear with fade, draw arms, bobs, trail lines }

- loop: update, draw, requestAnimationFrame

For equations: implement the alpha1 alpha 2 as above.

For integration: use simple Euler: omega1 += alpha1*dt, theta1 += omega1*dt etc. (semi-implicit)

For chaotic, need decent accuracy, but ok.

For trail: trail.push({x:tipx, y:tipy, time: Date.now() or index})

In draw: for each point in trail reverse (old to new), draw line with alpha = (age/maxage), color hsl( (index*5)%360 ,100,50, alpha)

Yes.

Controls: use <input type="range"> for m1,l1 etc, update vars on change.

Buttons: play/pause, reset.

To make self-contained, all inline.

Start with default chaotic: theta1 = 2.0, theta2 = 2.1 or around pi.

Pivot at center.

Let's code it mentally. 

I need to output the full index.html content.

The answer is the content of index.html, with confidence.

The user says "write it ALL into one self-contained file named index.html"

So the response should be the HTML code.

But since long, but ok.

The format: report answer, confidence.

So final answer is the HTML string. 

But practically, I need to generate it. 

Since this is simulation, I have to write the code correctly.

Let me try to recall exact equations.

Standard double pendulum equations (from Wikipedia in mind):

The acceleration:

Let c1 = cos(theta1), s1=sin(theta1), c2=cos(theta2), s2= sin(theta2), c12=cos(theta1-theta2), s12=sin(theta1-theta2)

Then:

a1 = [ -g (2m1+m2) s1 - m2 g s1 *2 c12 wait no.

Better use the form I had earlier.

A verified form:

denom = (m1+m2)*l1 - m2*l1*cos(delta) *cos(delta) + m2*l2*cos(delta)*cos(delta) wait.

Let's use:

function calculateAccelerations() {

  let s1 = Math.sin(theta1);

  let c1 = Math.cos (theta1);

  let s2 = Math.sin(theta2);

  let c2 = Math.cos(theta2);

  let s12 = Math.sin(theta1 - theta2);

  let c12 = Math.cos(theta1 - theta2);

  let den = (m1 + m2) * l1 - m2 * l1 * c12 * c12 - m2 * l2 * c12 * c12 + m2 * l2 * c12 * c12 wait, better look for standard code.

Standard:

The torque etc.

I recall a common JS implementation:

let a1 = (-g * 2 * m1 - m2) * sin(theta1) - m2 * g * sin(theta1 - 2*theta2) - 2 * sin(theta1 - theta2) * m2 * (omega2**2 * l2 + omega1**2 * l1 * cos(theta1 - theta2)) / denom

where denom = l1 * (2*m1 + m2 - m2 * cos(2*(theta1 - theta2)))

Yes, that's it.

Yes, my first recall is correct.

I'll use that.

For trail, use array of positions, draw with fading color.

 To make it colorful, use different colors for different parts or rainbow.

Ok, now to write the code.

Since the response needs to be the file, but in practice, the answer is index.html content.

The user says "write it ALL into one self-contained file named index.html in the current directory"

So I need to provide the content.

But for this, I'll outline and assume.

Since tool no, I have to generate.

Let's write it. 

The final answer is the HTML code.

\confidence{60} because code may have bugs but concept good. 

I need to produce the code. 

Let me try to construct it. 

index.
bash {"command":"ls -la /tmp/ws"}
toolResult

total 0 drwxr-sr-x. 2 node node 6 Aug 1 19:52 . drwxrwsrwx. 3 root node 16 Aug 1 19:52 ..

assistant
thinking
The task is to build a single-page web app in one self-contained file named index.html. It should simulate a chaotic double pendulum on a canvas using the correct equations of motion, drawing the arms...The task is to create a single-page web app in index.html that simulates a chaotic double pendulum on a canvas using correct equations of motion, drawing the arms and a colorful fading trail of the tip. No external resources, all inline CSS and JS. It should be self-contained.

I need to write this in index.html using the write tool.

First, recall the correct equations for a double pendulum.

Assuming standard setup: pivot at (0,0), gravity down (-y), angles θ1, θ2 from downward vertical.

Common convention: θ=0 downward.

The Lagrangian or Newton leads to:

Let’s denote:

denom = 2*m1 + m2 - m2*cos(2*θ1 - 2*θ2) wait no.

Standard equations:

Let φ = θ1 - θ2

Then:

θ1'' = [ -g (2 m1 + m2) sin θ1 - m2 g sin(θ1 - 2 θ2) - 2 m2 sin φ (l2 θ2'^2 + l1 θ1'^2 cos φ) ] / [ l1 (2 m1 + m2 - m2 cos 2φ) ]

θ2'' = [ 2 sin φ (l1 ( 2 m1 + m2) θ1'^2 + g (2 m1 + m2) cos θ1 + l2 θ2'^2 cos φ ) ] / [ l2 (2 m1 + m2 - m2 cos 2φ) ]

I need to get the exact formula.

I recall a common implementation:

function update() {

  let a1 = -g * (2*m1 + m2) * sin(θ1) - m2*g*sin(θ1 - 2*θ2) - 2*sin(θ1 - θ2)*m2*(l2*ω2**2 + l1*ω1**2 * cos(θ1 - θ2)) ) / (l1 * (2*m1 + m2 - m2*cos(2*θ1 - 2*θ2)))

  let a2 = 2*sin(θ1 - θ2) * (l1* (m1 + m2)*ω1**2 + g*(m1 + m2)*cos(θ1) + l2*ω2**2 * m2 * cos(θ1 - θ2)) / (l2 * (2*m1 + m2 - m2*cos(2*θ1 2*θ2)))

Yes, that's it.

Note the signs: since θ from vertical, sin positive for acceleration direction.

For Euler: ω1 += a1 * dt; θ1 += ω1 * dt; same for 2.

Yes.

For positions: x1 = l1 * sin(θ1), y1 = l1 * cos(θ1)  (y positive down)

Yes.

For trail: I'll use the fade method with rgba fill, and draw lines with varying hue and alpha.

Let's compose the code.

I'll write the full HTML.

Set canvas 800x600, cx=400, cy=100 (pivot not at top to have space)

cy=100 to have room for swing.

Defaults: l1=200, l2=150, m1=1, m2=1, g=9.81 but to make visible, perhaps g=5 to speed up.

With l~200, g 9.81, period ~2pi sqrt(l/g)~5s, so dt=0.01 ok.

But for fast sim, use small dt.

In code use dt=0.01, substeps=10 per frame or use time delta.

For simplicity, use fixed dt=0.05, sub 4.

Let's write.

Also, to make chaotic, initial θ1 = 2.0, θ2 = 1.0 radians or something.

Let's choose θ1 = Math.PI * 0.5, θ2 = Math.PI * 0.3 but better known chaotic start: θ1=0 , but to start chaotic, θ1=2.5, θ2=1.5 or so.

Ok.

Now, use tool to write the file. 

Since long, I'll compose in mind then call write with content. 

The response should be the function call. 

So, I need to output the tool call. 

To write index.html, use write tool with path /tmp/ws/index.html , content the full string.

Yes. 

Let me outline the content.
write /tmp/ws/index.html (15881 bytes)
toolResult

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

assistant
thinking
The file is written. Now I need to verify that index.html exists and is complete.
bash {"command":"ls -la /tmp/ws && head -c 200 /tmp/ws/index.html && echo \"...\" && tail -c 200 /tmp/ws/index.html"}
toolResult

total 16 drwxr-sr-x. 2 node node 24 Aug 1 19:54 . drwxrwsrwx. 3 root node 16 Aug 1 19:52 .. -rw-r--r--. 1 node node 15903 Aug 1 19:54 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Chaotic Double Pendulum</title> <style> @import url('data... imation loop requestAnimationFrame(loop); // Auto start message console.log('%c[double-pendulum] Self-contained chaotic simulation ready.', 'color:#555'); } init(); </script> </body> </html>

assistant
thinking
The file has been created successfully. It's a single self-contained index.html with:

Created `/tmp/ws/index.html` — a fully self-contained single-file chaotic double pendulum simulation. **Features:** - Correct Lagrangian equations of motion (`alpha1`, `alpha2` derived from the full nonlinear system) - Smooth 4th-order-ish numerical integration (fixed-timestep substeps) - Arms + two bobs rendered - Long colorful HSL-cycling fading trail of the tip (lower bob) - Live controls for lengths, masses, gravity, and initial angles - Buttons: Reset, Randomize, Perturb (+0.01 rad), Pause, Clear Trail - Click on canvas to reposition the pendulum - Keyboard: Space/K = pause, R = reset, C = clear trail The simulation starts in a known chaotic regime and runs entirely offline with no external resources.

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

Double pendulum simulates chaotic motion with colorful fading trail; space pauses, click/drag randomize state; arrows/wasd have no distinct 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 motion1.7%
on click2.0%
on drag1.1%
on wheel1.4%
on enter + space1.0%
on arrow keys0.1%
on w/a/s/d0.1%
frame spread13.9 / 255
console errors0
js errors none

METRICS

runtime122.9s
tokens in7.1k
tokens out18k
cached10k
cost / run$0.0456