Visualizations
310 / 500

310 · Physics

Double Pendulum

Pendulums that start almost identical and end up worlds apart.

A double pendulum is the classic chaotic system. Several are released from starting angles that differ by a tiny fraction of a degree, each integrated with the fourth-order Runge-Kutta method. For a few seconds they move as one, then their paths diverge completely, painting colorful traces of the lower bob.

Try it. Drag a bob to reposition it, then let go. Press R to restart.

  • Runge-Kutta integration
  • Lagrangian mechanics
  • Sensitive dependence

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a double pendulum chaos demo with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it a near-black background.
- Simulate one double pendulum: two rods of equal length and two equal point masses, with a state of four numbers (both angles and both angular velocities). Use the standard equations of motion derived from the Lagrangian; put the formulas in a small function that returns the derivatives.
- Integrate with the fourth-order Runge-Kutta method (RK4), taking about 10 small sub-steps per animation frame so energy stays steady.
- Draw the pivot, both rods and both bobs, scaled so the full reach fits the screen. Start with both arms raised well above horizontal so it swings wildly.
- Record the lower bob's recent positions and draw them as a trail behind it.

Once that works, show off the chaos:
- Run 7 to 9 pendulums at once from starting angles that differ by about 0.0002 radians, each with its own color from a rainbow of hues.
- Fade each trail from bright and thick at the head to dim and thin at the tail by drawing it in short chunks of falling opacity, and use globalCompositeOperation = "lighter" so the overlapping pendulums glow white while they still agree.
- Let me drag a bob to reposition all the pendulums together, then release them, and press R to restart from new random angles.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as plotting the divergence over time, a map that colors every starting pair of angles by how fast it flips, or adding damping and a driving force.
PreviousGene SurfingDrift at a growing colony's edge splits red and green bacteria into jagged sectors. NextPerfect SnakeA snake AI that can never crash, cutting safe shortcuts until it fills every cell.

Related visualizations

  • Magnetic PendulumFractals A pendulum over three magnets, and the fractal map of where every release point ends up.
  • Foucault PendulumPhysics A museum pendulum ploughs a rosette into sand as the Earth turns beneath it.
  • HarmonographGenerative art A Victorian pendulum machine inks decaying roses and stars onto cream paper.
  • FPUT RecurrencePhysics The 1955 computer experiment where a chain of masses refused to thermalize.
  • Three-Body BalletPhysics Twenty-two periodic three-body orbits, inked like calligraphy until a nudge breaks them.
  • Quantum Double SlitPhysics A quantum wave packet passes through two slits and interferes with itself.
  • Lagrange LandscapePhysics The restricted three-body problem as a plaster relief, Trojans looping on its summits.
  • Tumbling T-HandlePhysics A spinning T-handle in zero g flips end over end, again and again.
  • Quantum BilliardsPhysics A quantum wave packet bounces around chaotic billiards and leaves scars.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs