Turbulent air boils a star into speckles until adaptive optics snaps it sharp.
Two Kolmogorov phase screens, made once by shaping random noise with the k^(-11/6) turbulence spectrum and inverse FFT, drift across a 1.6 meter telescope's aperture on their own winds. Every frame the star's image is computed as the squared Fourier transform of the pupil field at 450, 550 and 650 nm, so the 1 ms exposure boils with colored speckles while the long exposure blurs into a seeing disk. Close the adaptive optics loop and a 10 by 10 Shack-Hartmann sensor images each subaperture with its own small FFT, turns spot centroids into slopes, and a least-squares reconstructor drives an 11 by 11 deformable mirror through a leaky integrator. The star collapses to a diffraction core with Airy rings and spider spikes, and the Strehl trace shows how much survives as wind and turbulence rise.
Try it. Click the star, the AO button, A or Space to open and close the loop. Drag the Turbulence and Wind sliders (or use the up and down and left and right arrows), drag on the wavefront panel to steer the wind, and press R to restart the long exposure.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a simulation of why stars twinkle in a telescope, using 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 and stays sharp on high-DPI screens with a big "focal plane" view and a small "wavefront" view.
- Write a small radix-2 FFT yourself, plus a 2D version that transforms rows and then columns.
- Make a 128 x 128 turbulent phase screen: fill a frequency grid with random complex numbers scaled by k^(-11/6) (k is the distance from zero frequency), inverse FFT it, keep the real part, and scale it so the phase varies by several radians across 32 pixels.
- Each frame, slide a 32-pixel circular pupil across the screen (that is the wind). Build a 128 x 128 complex field that is exp(i * phase) inside the pupil and 0 outside, FFT it, and draw the squared magnitude, shifted so the center is in the middle, as the star image. Use a log brightness curve.
- Draw the pupil's phase in the wavefront view with a blue to orange color map.
Once that works, make it beautiful:
- Keep a running average of the star images as a long exposure next to the speckles, so the boiling pattern turns into a blurry seeing disk.
- Add a simple adaptive optics toggle: fit and subtract the average tilt and a low-resolution version of the phase (for example an 8 x 8 block average), and watch the star snap into a sharp core with rings.
- Add sliders for wind speed and turbulence strength, and show the Strehl ratio (peak brightness divided by the perfect-pupil peak).
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 rendering three wavelengths for colored speckles, a real Shack-Hartmann sensor with a small FFT per lenslet, or a central obstruction and spider vanes for diffraction spikes.