Build an Interactive Double-Pendulum Chaos Visualizer in HTML

Create a single-file HTML5 Canvas double-pendulum simulator with RK4 physics, draggable bobs, gravity presets, trail controls, and a twin-pendulum divergence mode.

You getone complete HTML file in a single code block, then 3 short ideas to extend it.

The prompt

Prompt
Act as a senior creative technologist and physics simulation developer. Build an original, self-contained interactive web app called Double-Pendulum Chaos Lab in a single HTML file.

Core mechanic: Simulate a double pendulum using fourth-order Runge-Kutta (RK4) numerical integration on an HTML5 Canvas, with a toggleable twin pendulum offset by 0.001 radians to visualize chaotic divergence.

Follow these rules:
1. Interactive controls: Allow users to drag either pendulum bob directly on the canvas with mouse or touch to set starting angles, plus Play/Pause, Reset, and Clear Trail buttons, and Space/R/T keyboard shortcuts.
2. Physics and presets: Include gravity preset buttons for Earth, Moon, and Jupiter, and a trail fade slider.
3. Live telemetry: Display real-time angle readouts and the divergence angle between the primary and twin pendulums.
4. Layout and theme: Use a clean dark laboratory palette with high-contrast cyan and magenta trails, responsive from 360px to 1280px with no horizontal overflow.
5. Accessibility and constraints: Respect prefers-reduced-motion, use zero external libraries, fonts, network calls, localStorage, or form tags, and wrap all JavaScript in an IIFE.

Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.

Example output

One HTML file. Save it and open it in any browser.Open full screen
At a glanceDouble-Pendulum Chaos Lab featuresSingle-file HTML5 canvas simulator
Gravity presets
3 presets
Earth, Moon, Jupiter
Twin pendulum offset
0.001 rad
Starting difference that diverges rapidly
Physics integrator
RK4
Draggable bobs set starting angles
Keyboard shortcuts
3 keys
Space pause, R reset, T twin

Example: Double-Pendulum Chaos Lab, an RK4 physics visualizer with draggable bobs and twin-pendulum divergence.

Drag either bob on the canvas to set custom starting angles, then release to watch the chaotic motion unfold. Switch between Earth, Moon, and Jupiter gravity presets, adjust the Trail Fade slider, or toggle Twin Divergence to see how a 0.001-radian offset rapidly separates two identical pendulums. Press Space to pause, R to reset, or T to toggle the twin.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Specifying RK4 integration prevents energy drift and keeps the pendulum motion smooth and physically believable.
  • Requiring pointer-based bob dragging makes the chaos intuitive to explore without complex angle input fields.
  • Isolating all logic in an IIFE with zero external dependencies guarantees the file runs offline on the first try.

Paste this prompt into Gemini, ChatGPT, or Claude. Save the generated code as pendulum-chaos.html and open it in any modern browser, or preview it directly in Canvas or Artifacts.

Common edits

  • Add Web Audio API chime triggers whenever the lower bob crosses the vertical axis.
  • Include sliders for rod lengths and bob masses to explore asymmetric pendulum ratios.

Make it repeatable

Keep using this prompt without pasting it in every time.

Keep exploring

More in Animations & Effects