oneshotlm
Compare all models on this prompt →

Double pendulum · gpt-oss-120b

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 · 4 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
We need to create a single-page web app with a canvas that simulates a chaotic double pendulum, with correct equations of motion, drawing arms and a colorful fading trail of the tip. Must be self-contained in index.html.

We need to write the file with HTML, CSS (in style tag), and JS (in script tag). Provide the simulation.

We need to compute equations: double pendulum with masses m1,m2, lengths l1,l2, angles theta1,theta2, angular velocities omega1,omega2. Equations from standard physics:

Let g gravity.

Define:

num1 = -g*(2*m1 + m2)*sin(theta1);
num2 = -m2*g*sin(theta1 - 2*theta2);
num3 = -2*sin(theta1 - theta2)*m2;
num4 = omega2*omega2*l2 + omega1*omega1*l1*cos(theta1 - theta2);
den = l1*(2*m1 + m2 - m2*cos(2*theta1 - 2*theta2));

alpha1 = (num1 + num2 + num3*num4) / den;

Similarly for alpha2:

num1 = 2*sin(theta1 - theta2);
num2 = (omega1*omega1*l1*(m1 + m2));
num3 = g*(m1 + m2)*cos(theta1);
num4 = omega2*omega2*l2*m2*cos(theta1 - theta2);
den = l2*(2*m1 + m2 - m2*cos(2*theta1 - 2*theta2));

alpha2 = (num1*(num2 + num3 + num4)) / den;

Actually the standard set:

den1 = l1 * (2*m1 + m2 - m2 * Math.cos(2*theta1 - 2*theta2));
a1 = (-g*(2*m1 + m2)*Math.sin(theta1) - m2*g*Math.sin(theta1 - 2*theta2) - 2*Math.sin(theta1 - theta2)*m2*(omega2*omega2*l2 + omega1*omega1*l1*Math.cos(theta1 - theta2)))/den1;

den2 = l2 * (2*m1 + m2 - m2 * Math.cos(2*theta1 - 2*theta2));
a2 = (2*Math.sin(theta1 - theta2)*(omega1*omega1*l1*(m1 + m2) + g*(m1 + m2)*Math.cos(theta1) + omega2*omega2*l2*m2*Math.cos(theta1 - theta2)))/den2;

We'll implement using RK4 or simple Euler with small dt.

We'll also draw a fading trail of tip (the second mass). The trail: we can keep an array of points and draw with decreasing alpha.

We'll implement requestAnimationFrame.

Add UI perhaps not needed.

Set canvas size e.g., full window.

We'll also use CSS body margin:0.

Implement color cycling: hue based on time.

Implementation steps:

- HTML with canvas id="canvas"

- JS: set up canvas resizing to window.

- Define parameters: m1=10, m2=10, l1=200, l2=200, gravity=9.81.

- Initialize angles: theta1 = Math.PI/2, theta2 = Math.PI/2 + 0.01 maybe.

- Angular velocities: 0.

- dt=0.05

- trail array limit maybe 2000 points.

- In animation loop: compute angular accelerations a1,a2 using formulas, update velocities and angles via simple integration: omega1 += a1*dt; theta1 += omega1*dt; similarly for omega2.

- Compute positions: x1 = origin.x + l1 * sin(theta1); y1 = origin.y + l1 * cos(theta1); (since vertical down positive y)

- x2 = x1 + l2 * sin(theta2); y2 = y1 + l2 * cos(theta2);

- Add tip point to trail.

- Draw: fade overlay using semi-transparent rectangle maybe to achieve fading effect, but they want colorful fading trail, we could draw trail points with decreasing alpha.

Simplify: each frame, draw a semi-transparent black rectangle over canvas with low opacity to create fade effect, then draw arms and the tip in bright color.

Alternatively maintain trail array and draw each with alpha proportional to age and hue cycles.

Simplify: Use globalCompositeOperation = 'lighter' maybe.

We'll just implement fade rectangle.

Add color: Hue based on time for the tip and trail line segment.

Implementation details:

In each frame:

ctx.fillStyle = 'rgba(0,0,0,0.1)'; // fade

ctx.fillRect(0,0,width,height);

Then set stroke style for arms: e.g., '#fff'.

Draw line from origin to (x1,y1) etc.

Then draw line from (x1,y1) to (x2,y2).

Then draw tip: ctx.beginPath(); ctx.arc(x2,y2,5,0,2*Math.PI); ctx.fillStyle = `hsl(${(time*0.1)%360},100%,50%)`; ctx.fill();

Also draw trail: keep history of x2,y2 points. For each point, draw small circle with decreasing alpha/hue.

Simplify: use trail array, each point {x,y,time}.

draw loop: for(let i=0;i<trail.length;i++) { let p = trail[i]; let age = (now - p.time); let alpha = Math.max(1 - age/5,0); // last 5 seconds

ctx.fillStyle = `hsla(${(p.time*30)%360},100%,50%,${alpha})`; ctx.fillRect(p.x, p.y,1,1); // or small circle.

But using fade overlay may be enough.

Let's produce final index.html.

We need to ensure code runs sandboxed. No external resources.

We'll provide file via write.

write index.html (4145 bytes)
toolResult

Successfully wrote 4145 bytes to index.html

assistant

Implemented a complete, self‑contained double pendulum simulation: - **HTML** with a `<canvas>` element. - **CSS** for full‑screen, no‑margin layout. - **JavaScript**: - Accurate equations of motion for a double pendulum. - Simple symplectic Euler integration. - Responsive canvas resizing. - Colorful, fading trail of the pendulum tip. - Real‑time drawing of arms and masses with dynamic hues. All code resides in a single `index.html` file ready to run offline. Enjoy the chaotic motion!

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

modelgpt-oss-120b
vendorOpenAI
harnesspi-agent
generated2026-07-22

EVALUATION

3/5 working

Double pendulum swings and traces a colorful fading trail, but stays confined to a small screen area.

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.0%
on click2.4%
on drag2.7%
on wheel1.3%
on enter + space2.3%
on arrow keys2.0%
on w/a/s/d2.2%
frame spread11.7 / 255
console errors0
js errors none

METRICS

runtime59.6s
tokens in5.1k
tokens out2.8k
cached0
cost / run$0.0007