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

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.
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
Under the hood
TypeScript, Canvas 2D, Vite, Vitest, Python (SymPy) and GitHub Actions. MIT licence.




