Double pendulum · solar-pro4
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.
transcript · 4 messages
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.
thinking
The user wants me to create a single-page web app that simulates a chaotic double pendulum using the correct equations of motion. Let me build this with: 1. Physics: Double pendulum using Lagrangian mechanics (the classic coupled ODEs) 2. Canvas rendering: Arms, tips, and a colorful fading trail 3. All in one index.html file The equations of motion for a double pendulum are well-known. I'll use the standard formulation: For a double pendulum with masses m1, m2, lengths L1, L2, angles θ1, θ2, and gravity g: The equations (from the Lagrangian) are: θ1'' = (-g(2m1+m2)sin(θ1) - m2·g·sin(θ1-2θ2) - 2sin(θ1-θ2)·m2·(θ2'^2·L2 + θ1'^2·L1·cos(θ1-θ2))) / (L1·(2m1+m2 - m2·cos(2θ1-2θ2))) θ2'' = (2sin(θ1-θ2)·(θ1'^2·L1·(m1+m2) + g·(m1+m2)·cos(θ1) + θ2'^2·L2·m2·cos(θ1-θ2))) / (L2·(2m1+m2 - m2·cos(2θ1-2θ2))) I'll implement this with a symplectic-like integration (Verlet or RK4 for stability). Actually, for a double pendulum, simple Euler or RK4 works fine for visualization purposes. Let me use RK4 for accuracy. For the trail, I'll use a fading effect - draw circles with decreasing opacity, and use a rainbow/hue that shifts based on position or time. Let me create this.
/tmp/ws/index.html (8765 bytes)Successfully wrote 8765 bytes to /tmp/ws/index.html
thinking
The file has been written. Let me verify it looks correct and provide a summary.
The file is ready at `/tmp/ws/index.html`. Here's what it does: **Physics:** - Uses the full **Lagrangian equations of motion** for a double pendulum (with `m1`, `m2`, `L1`, `L2`, `g` as tunable parameters) - Integrates with **RK4** (4th-order Runge-Kutta), doing 2 sub-steps per frame for accuracy - The two sliders set initial angles θ₁ and θ₂; Reset re-initializes from current slider values **Visuals:** - Dark canvas with a subtle vignette and faint grid - Two arms drawn as glowing lines (blue-ish for arm 1, orange-ish for arm 2) - Two masses rendered as radial-gradient orbs with glow - **Colorful fading trail** — up to 800 points, hue cycles continuously, alpha fades from 5% (oldest) to 60% (newest), line width grows from 1→4px along the trail - A glowing tip dot at the end of the trail **Controls:** - **θ₁ / θ₂ sliders** — set initial angles and restart - **Reset** — clears trail and resets velocities to zero - **Pause/Play** — freezes the simulation Open it directly in a browser (no server needed) to watch the chaos unfold.
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
EVALUATION
Double pendulum sim with colorful fading trails animates continuously; sliders/reset/pause present but pendulum unaffected by pointer/keyboard input.
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.