Skip to content
Back to the surface

Chaos Lab

A double pendulum you throw by hand, and 2,000 more to watch chaos happen.

2,000
pendulums at once
10⁻⁷
rad apart
RK4
from the Lagrangian
Role
Solo
Stack
TypeScriptSymPyCanvas 2DVitest
Chaos Lab

The problem

A double pendulum is the simplest machine that turns chaotic. Two rods, two weights, and after a few seconds there is no way to say where they will be. I wanted that to feel physical: something you throw with your hand and watch fall apart.

What it does

It runs in the browser in real time. You grab the bobs and throw them, change gravity mid-swing, rewind the motion, or launch up to 2,000 pendulums a ten-millionth of a radian apart and watch them split.

Fig. 1 · Two double pendulums, released 10⁻⁵ rad apart. Drag them, let go, and wait.

How it works

The equations of motion come straight from the Lagrangian, derived symbolically with SymPy and generated as code, then integrated with a fourth-order Runge–Kutta scheme at a fixed time step.

Where it started

In March 2023, during prépa, it was a short Python script. In November 2026 it was rebuilt from scratch for the web, with tests.

What's inside

  • Physics derived symbolically from the Lagrangian with SymPy, then generated as TypeScript, joint damping included
  • Fixed-step RK4 integrator at 600 steps per second, with energy drift around 10⁻⁷ shown live
  • Exact rewind from a history buffer, not a backwards integration
  • Glowing trails coloured by speed or time, live controls for gravity (Moon to Jupiter), masses, lengths and damping, presets, keyboard shortcuts, phone layout
  • Tests that check the equations against the textbook closed form, energy conservation, exact rewind and divergence
  • One-command installers for Linux and Windows with a desktop shortcut, tested on every push by GitHub Actions on real Linux and Windows machines

In the simulator

A single chaotic pendulum
A single chaotic pendulum. The lower bob draws a glowing trail coloured by its speed. The panel shows angles, speeds and the energy drift.
The butterfly effect, 1,000 pendulums
The butterfly effect, 1,000 pendulums. 1,000 pendulums started 10⁻⁷ rad apart. They moved as one for 12 seconds, and now they are flying apart.
The 2023 experiment, live
The 2023 experiment, live. The setup of my first Python script, now running in real time: 100 pendulums offset by 10⁻⁴ rad.
On a phone
On a phone. The panel folds away and the controls stay at hand.

Under the hood

TypeScript, Canvas 2D, Vite, Vitest, Python (SymPy) and GitHub Actions. MIT licence.