Visualizations
303 / 500

303 · Physics

Quantum Billiards

A quantum wave packet bounces around chaotic billiards and leaves scars.

The Schrodinger equation is solved on a 256 x 128 grid with the split-operator Fourier method: every step applies the kinetic energy exactly in momentum space with a pair of FFTs and the walls as a tall potential in position space. The packet starts as a coherent beam, then reflects into an interference pattern that fills the table, colored by phase, while a classical ball with the same start bounces along. Summing psi(t) times e^(iEt) over the run filters out the part of the packet at one energy, an almost stationary state; in the chaotic stadium, a packet launched along the unstable diamond orbit leaves a bright scar along that orbit, the effect Eric Heller discovered in 1984. The inset shows |psi(k)|^2 straight from the FFT, a ring at the energy shell.

Try it. Drag and release to launch a packet from any point, with longer flicks giving shorter wavelengths. Press 1 to 5 for the stadium, circle, cardioid, mushroom and Sinai tables, A to cycle between the wave, its time average and the energy-filtered state, B to hide the classical ball, and Space for the next scene.

  • Split-operator FFT
  • Spectral filtering
  • Domain coloring
  • Signed distance walls

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 quantum billiards simulation 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 near black.
- Store a complex wavefunction on a 128 x 128 grid as two Float64Arrays (real and imaginary parts). Use units where hbar, the mass and the grid spacing are all 1.
- Write an in-place radix-2 FFT yourself, and a 2D version that transforms every row and then every column.
- Define a stadium (a rectangle with semicircular ends) with a signed distance function. Set the potential to 0 inside and about 4 outside.
- Advance with the split-operator method: multiply by exp(-i V dt), FFT, multiply each wave vector by exp(-i k^2 dt / 2), inverse FFT. Use dt = 0.5.
- Start with a Gaussian wave packet times exp(i k0 x) with k0 around 1. Draw each cell with hue from the phase and brightness from the magnitude into an ImageData, and scale it up to the screen.

Once that works, make it beautiful:
- Draw the table outline as a crisp vector curve on top and darken everything outside it.
- Let me drag and release to launch a new packet in that direction, and add a classical ball that starts with the same position and velocity and reflects off the walls.
- Keep a running time average of |psi|^2 and add a key to switch to it with a warm heat map.

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 comparing a circle with the stadium, filtering psi(t) at one energy to reveal quantum scars, or showing |psi(k)|^2 from the FFT as a momentum-space inset.
PreviousDancing LinksKnuth's Algorithm X tiles boards with wooden pentominoes while its links visibly dance. NextHidden 3DA live magic eye picture: a turning 3D sculpture hidden in colorful noise.

Related visualizations

  • Quantum Double SlitPhysics A quantum wave packet passes through two slits and interferes with itself.
  • Dynamical BilliardsPhysics A fan of 1,000 balls in reshapable tables, linked live to the Birkhoff phase map.
  • Faraday WavesFluids A shaken dish of liquid locks into stripes, squares, hexagons and a 12-fold quasicrystal.
  • Pool CausticsPhysics Sunlight bent by a rippling pool surface draws a living net of light on the tiles.
  • Hydrogen OrbitalsPhysics Exact hydrogen wavefunctions as glowing 3D point clouds, colored by quantum phase.
  • Cosmic WebAstronomy Noise grows into the filaments, voids and clusters of the universe.
  • Fourier DarkroomMath Paint on a picture's 2D spectrum and watch the inverse FFT redraw it instantly.
  • Bubble ChamberPhysics Archival film of particle tracks: tightening spirals, V decays and pairs.
  • Pool Trick ShotsGames Billiards with real spin physics and an AI that plans by simulating every shot.

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

← More from Emergent Mind Labs