How 102,400 pendulums drew a ghost
This is the picture from my Halloween post. Every dot in it is a double pendulum (EXTERNAL · article ↗): one pendulum hanging from the end of another. They all run live in your browser on this page, so you can watch the ghost get made.
Stage 1: one pendulum, one dot
Hold both arms out at some pair of angles and let go. Gravity does the rest. I record one thing: the first moment either arm swings over the top. That's a flip.
The map has one dot per pendulum. Where the dot sits says how the arms started: across is the upper arm, from -180 to 180 degrees, and down is the lower arm, from 180 at the top to -180 at the bottom. Its color says how long the flip took. Click anywhere on the map and that pendulum drops in beside it.
Stage 2: why the swirls are so fine
These two pendulums start 0.001 radians apart on the lower arm, about a twentieth of a degree. You can't see the difference. For a while they move as one, then they don't, and one flips more than three times later than the other. That's chaos, and it's why the map has thin swirls and speckled edges: dots side by side can be completely different pendulums.
first pendulum
second pendulum
Stage 3: a row of them
Here are 24 pendulums from one row of the map: same lower arm, with the upper arm stepping across. Each swings until it flips, then drops its dot and goes grey. The strip at the bottom is that whole row from the real map, all 320 dots. Do that for 320 rows and you have the picture.
Stage 4: all 102,400 at once
This plays the real results as a time-lapse. Dark means no flip yet. The fast flips land in the corners first, and the color creeps inward toward the middle. The clock runs on a log scale, meaning each second of watching covers a bigger stretch of the run than the last, because the early flips would otherwise be over in a blink. Drag the slider to move through time yourself.
Stage 5: what's inside the ghost
White means one of two things, shown here in two colors.
31,392 can't flip at all. Let go at rest, a pendulum has a fixed amount of energy, and these don't have enough to carry an arm over the top. A one-line check finds them: 2 cos(upper) + cos(lower) above 1. The program never simulates them. They're the ghost's body, and the formula draws its outline.
3,435 ran out of time. These had enough energy but didn't flip in the 200 time units I gave them. They're the speckles and the two little arms.
The other 67,573 flipped. So "couldn't get over it" is exact for the blue dots: the physics rules it out.
Stage 6: checking the result
I build plimsoll (EXTERNAL · source repo ↗), a sandbox for running code you don't fully trust, like code an AI wrote. So I split the map into 256 tiles of 20 by 20 pendulums and ran each tile twice, once in a Docker sandbox under runc (EXTERNAL · source repo ↗) and once under gVisor (EXTERNAL · official docs ↗), which puts a second kernel of its own between the code and the machine. All 256 tiles came back identical.
That shows the two sandboxes gave the program the same math. It says nothing about how well either one would hold in hostile code; that's a different test.
The numbers
| What | Value |
|---|---|
| Pendulums | 102,400 (320 by 320) |
| Flipped | 67,573 |
| Had the energy, no flip in time | 3,435 |
| Can't flip, not simulated | 31,392 |
| Length of a run | 10,000 steps of 0.02, so 200 time units, about 32 swings of a single pendulum |
| Setup | Equal arms and weights, gravity divided by arm length set to 1, released at rest, angles measured from straight down |
| Method | Fourth-order Runge-Kutta (EXTERNAL · article ↗), a standard way to follow motion in small steps |
| Sandbox check | 256 tiles, 512 runs, all 256 identical |
The map on this page comes from flipmap.mjs (INTERNAL · the program →), 42 lines of JavaScript with the same math as the sandbox run, about ten seconds on my laptop. The pendulums you see moving run those same equations in your browser.
One wrinkle, and I like it. JavaScript lets each engine work out sine and cosine its own way in the very last digit, and Chrome's last digit isn't always the one in node, which made this map. I recomputed every simulated pendulum in Chrome: 102 of 71,008 came out differently, none before time 119. So a pendulum you click can, rarely, disagree with its own dot. That's Stage 2 happening to the page itself.
Two choices shape what you see: the color scale is logarithmic so the slow and fast flips both show detail, and the picture would change a little with a longer run, since more of the red dots might flip.