A train, a tunnel and a light clock, with a live Minkowski diagram in either frame.
A train that is longer than a tunnel at rest races through it at 0.8 c. The scene and the Minkowski diagram below it share one horizontal scale and come from the same events: every worldline is defined once in the platform frame, then Lorentz transformed into whichever frame you view from, and the scene is simply where each worldline crosses the line of 'now'. That is why the moving train contracts and fits, why its clocks disagree (the rear clock reads ahead), and why the photon in its light clock zigzags. Switch frames and the diagram shears smoothly from one set of axes to the other: for the platform both tunnel doors shut at the same instant with the whole train inside, but for the train the tunnel is the short one and the doors shut at different times, the barn and pole paradox resolved. A flash from the middle of the train reaches both ends together only in the train's own frame.
Try it. Switch between the platform and train frames, drag the speed slider (or press Left and Right), and press Flash, click the scene or press F to send a light flash from the middle of the train. Drag the diagram up or down to scrub through time.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build an interactive special relativity diagram 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, on a warm paper-colored background with crisp ink lines.
- Use units where c = 1. A train of rest length 10 moves at v = 0.8 along a platform. Define everything in the platform frame as worldlines x = x0 + w t: the train's front and back move with w = v, platform posts with w = 0.
- Draw a Minkowski diagram: x across, time up, same scale on both axes so light moves at 45 degrees. Draw the train's worldlines as a shaded band, the posts as vertical lines, and a light cone.
- Above the diagram, using the same horizontal scale, draw the scene at the current time: a horizontal "now" line moves up the diagram, and each object is drawn where its worldline crosses it.
Once that works, make it beautiful:
- Add a viewing frame with speed u and Lorentz transform every event before drawing it: t' = gamma (t - u x), x' = gamma (x - u t). A button switches between the platform frame and the train frame, animating u smoothly so the diagram shears from one set of axes to the other.
- Put a clock on each train car showing train time gamma (t - v x) at its event on the now line, and clocks on the platform showing platform time. Watch them disagree.
- Add a tunnel shorter than the train, with doors that shut at the same platform time, and a button that fires a light flash from the middle of the train.
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 a light clock whose photon zigzags, the twin paradox with a turnaround, or calibration hyperbolas on the axes.