oneshotlm
Compare all models on this prompt →

Double pendulum · deepseek-v4-pro

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 user wants me to create a single-page HTML file that simulates a chaotic double pendulum on a canvas. I need to:

1. Use correct equations of motion (Lagrangian mechanics for the double pendulum)
2. Draw the two arms
3. Draw a colorful fading trail of the tip (the end of the second pendulum)

Let me write the physics:

For a double pendulum with:
- m1, m2: masses
- L1, L2: lengths
- θ1, θ2: angles from vertical
- g: gravity

The equations of motion can be derived from Lagrangian mechanics. The standard form is:

Let:
Δ = θ2 - θ1

The angular accelerations are:

θ1'' = (m2*g*sin(θ2)*cos(Δ) - m2*sin(Δ)*(L1*θ1'²*cos(Δ) + L2*θ2'²) - (m1+m2)*g*sin(θ1)) / (L1*(m1 + m2*sin(Δ)²))

θ2'' = ((m1+m2)*(L1*θ1'²*sin(Δ) - g*sin(θ2) + g*sin(θ1)*cos(Δ)) + m2*L2*θ2'²*sin(Δ)*cos(Δ)) / (L2*(m1 + m2*sin(Δ)²))

I'll use RK4 integration for accuracy.

For the trail, I'll store positions of the tip and draw them with fading colors (HSL cycling) and opacity gradient.

Let me build this out fully.
bash {"command":"ls /workspace"}
toolResult

(no output)

assistant
thinking
The workspace is empty. Let me create the index.html with the double pendulum simulation.
write /workspace/index.html (11705 bytes)
toolResult

Successfully wrote 11705 bytes to /workspace/index.html

assistant
thinking
Let me verify the file was created successfully and review it for any issues.

The physics equations I used:

For the double pendulum Lagrangian:

T = ½ m1 L1² θ1'² + ½ m2 [L1² θ1'² + L2² θ2'² + 2 L1 L2 θ1' θ2' cos(θ2-θ1)]
V = -(m1+m2) g L1 cos(θ1) - m2 g L2 cos(θ2)

The equations of motion in my code look correct. Let me double check...

The standard equations for a double pendulum are:

θ1'' = [m2 g sin(θ2) cos(Δ) - m2 sin(Δ)(L1 θ1'² cos(Δ) + L2 θ2'²) - (m1+m2) g sin(θ1)] / [L1 (m1 + m2 sin²(Δ))]

θ2'' = [(m1+m2)(L1 θ1'² sin(Δ) - g sin(θ2) + g sin(θ1) cos(Δ)) + m2 L2 θ2'² sin(Δ) cos(Δ)] / [L2 (m1 + m2 sin²(Δ))]

Where Δ = θ2 - θ1

Let me verify my code:

```
const num1 = m2 * g * Math.sin(th2) * cd
           - m2 * sd * (L1 * om1 * om1 * cd + L2 * om2 * om2)
           - (m1 + m2) * g * Math.sin(th1);
const alpha1 = num1 / (L1 * denom);
```

denom = m1 + m2 * sd * sd = m1 + m2 sin²(Δ)

num1 = m2 g sin(θ2) cos(Δ) - m2 sin(Δ)(L1 θ1'² cos(Δ) + L2 θ2'²) - (m1+m2) g sin(θ1)

That matches! ✓

```
const num2 = (m1 + m2) * (L1 * om1 * om1 * sd - g * Math.sin(th2) + g * Math.sin(th1) * cd)
           + m2 * L2 * om2 * om2 * sd * cd;
const alpha2 = num2 / (L2 * denom);
```

num2 = (m1+m2)(L1 θ1'² sin(Δ) - g sin(θ2) + g sin(θ1) cos(Δ)) + m2 L2 θ2'² sin(Δ) cos(Δ)
alpha2 = num2 / (L2 * (m1 + m2 sin²(Δ)))

That matches! ✓

The equations look correct.

For the inverse kinematics when grabbing: I use the law of cosines to find the elbow angle, then compute θ1 and θ2. The elbow-down configuration (θ2_ik positive, psi subtracted) gives the natural downward-hanging pose. Looks right.

The trail is a colorful fading trail using HSL with cycling hue. The trail points fade from full opacity to fully transparent as they age. The current tip has a radial glow.

Looks good. Let me verify the file is there.
bash {"command":"wc -l /workspace/index.html && head -5 /workspace/index.html"}
toolResult

393 /workspace/index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">

assistant
thinking
The file looks good. Let me provide a summary to the user.

Done. **`/workspace/index.html`** — a self-contained, zero-dependency double pendulum simulator. **What's inside:** - **Physics:** Correct Lagrangian-derived equations of motion for the double pendulum, integrated with 4th-order Runge-Kutta at 4 sub-steps per frame for stable, accurate chaotic dynamics. - **Visuals:** Two pendulum arms drawn from a fixed pivot, a colorful HSL-cycling fading trail (oldest points are transparent, newest are bright), a radial glow halo at the current tip, and a subtle grid background. - **Interaction:** - **Click** anywhere to randomize initial angles (new chaotic trajectory). - **Drag** the tip to manually move the pendulum with inverse kinematics, then release to fling it with the mouse velocity. - Touch support for mobile. - **Energy bar** at bottom-left shows total mechanical energy with a color gradient. Open `index.html` in any browser — no server, no network, no CDN required.

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

modeldeepseek-v4-pro
vendorDeepSeek
harnesspi-agent
generated2026-07-08

EVALUATION

4/5 working

Double pendulum swings continuously with colorful fading tip trail; click and drag restart/fling it as labeled.

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.3%
on click1.3%
on drag1.2%
on wheel1.0%
on enter + space1.1%
on arrow keys1.5%
on w/a/s/d1.6%
frame spread6.2 / 255
console errors0
js errors none

METRICS

runtime100.5s
tokens in7.4k
tokens out5.5k
cached9.2k
cost / run$0.0080