Visualizations
071 / 500

071 · Physics

Quantum Double Slit

A quantum wave packet passes through two slits and interferes with itself.

This solves the time-dependent Schrodinger equation on a grid. An electron starts as a wave packet, moves toward a wall with two slits, and passes through both at once. On the far side the two waves interfere, and detections build up on a screen into bright and dark fringes. Brightness shows probability and hue shows the phase of the wave.

Try it. Click to fire a new electron from the pointer, or press Space. Press 1 or 2 for one or two slits, and C to clear the screen.

  • Schrodinger equation
  • Finite differences
  • Phase coloring

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 double slit simulation with JavaScript and the HTML canvas element by solving the time-dependent Schrodinger equation on a grid. 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:
- Use a grid of about 300 by 200 cells and store the wave function as two Float32Arrays, the real part R and the imaginary part I. Use units where hbar = m = 1 and the cell size is 1.
- Start a Gaussian wave packet on the left moving right: amplitude exp(-(dx^2 + dy^2) / (2 sigma^2)) times cos(k x) for R and sin(k x) for I (wavelength about 6 cells).
- Advance it with Visscher's leapfrog scheme: R += dt * H I, then I -= dt * H R, where H psi = -0.5 times the 5-point Laplacian of psi. Use dt = 0.3.
- Add a wall a third of the way across: cells where R and I are forced to zero, with two narrow gaps.
- Draw each cell with brightness from the amplitude sqrt(R^2 + I^2) and hue from the phase atan2(I, R).

Once that works, make it beautiful and physical:
- Add absorbing borders: multiply R and I by a factor slightly below 1 near the edges so waves do not bounce back.
- Give the far side of the wall its own brightness scale so the faint transmitted wave shows.
- Put a detector screen on the right. Every step, read |psi|^2 along its column and draw random detection dots from that distribution, a few at a time, so the interference fringes build up dot by dot. Fire a new electron every couple of seconds.
- Press 1 or 2 to switch between one and two slits.

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 which-path detector that destroys the fringes, tunneling through a thin barrier, or a split-operator solver using an FFT.
PreviousLightningBranching lightning that grows from a dielectric breakdown model. NextPoint-Light WalkerThirteen dots on black, and you see a person walking, running, dancing or carrying a box.

Related visualizations

  • Quantum BilliardsPhysics A quantum wave packet bounces around chaotic billiards and leaves scars.
  • InterferometerPhysics A Michelson interferometer: nudge a mirror by nanometers or send a gravitational wave.
  • Faraday WavesFluids A shaken dish of liquid locks into stripes, squares, hexagons and a 12-fold quasicrystal.
  • Phased ArrayPhysics Steer and focus a beam of sound with per-speaker delays in a live 2D wave simulation.
  • Hydrogen OrbitalsPhysics Exact hydrogen wavefunctions as glowing 3D point clouds, colored by quantum phase.
  • MoireIllusions Two sheets of fine lines beat into giant ghosts, and hide a secret message.
  • SolitonsFluids Solitary waves in a canal pass through each other unchanged, drawn as a Victorian plate.
  • Aperture DiffractionPhysics Draw any aperture and see its diffraction pattern in true spectral color.
  • HologramPhysics Record an off-axis hologram of glowing points, then rebuild the 3D scene from it.

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

← More from Emergent Mind Labs