Drag the sun over the dunes; ghosts traced through a real lens follow it.
The flare comes from a classic 50 mm double Gauss prescription: ten glass surfaces and an aperture stop. Every pair of surfaces makes a ghost (light reflected off one, back off another, then forward to the sensor), and each path is traced with paraxial ray-transfer matrices to find where the ghost sits on the line through the frame center and how large the aperture's image becomes. Ghosts take the shape of the blades, are clipped into crescents by the lens barrel off axis, and are tinted by the thin-film reflectance of their anti-reflection coatings. The sun adds a diffraction starburst whose spike count follows the blade count, veiling glare, lit-up dust and, in anamorphic mode, a blue horizontal streak. The dune field is a heightmap rendered with a column ray marcher and relit from the sun every time it moves, and dunes can hide the sun.
Try it. Drag the sun anywhere, including behind a dune ridge. The controls panel, which unfolds when you hover or tap, sets blade count, f-stop, coating (multi, single or none), spherical or anamorphic glass and lens dust. The inset traces the highlighted ghost's path through the lens. Keys: arrows move the sun, B blades, C coating, A anamorphic, D dust, [ and ] the f-stop.
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 lens flare over a desert sky 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 it. Paint a sky gradient and a few layers of sand-colored dune silhouettes made from sine waves.
- Put a bright sun where the pointer drags it, with a soft radial-gradient glow.
- Lens ghosts lie on the line through the sun and the center of the frame. Make a list of about 12 ghosts, each with a position multiplier m (for example between -1.5 and 2), a radius and a color. Draw each one at center + m * (sun - center) as a soft polygon with "lighter" blending, so they slide along the axis as the sun moves.
- Fade the whole flare out when the sun goes behind a dune by testing a few points on the sun's disc against the dune heights.
Once that works, make it beautiful:
- Pre-render a starburst: thin spikes perpendicular to the aperture blades (an even blade count gives that many spikes, an odd count twice as many) that get longer as you stop down.
- Shade the dunes from the sun's direction so slopes facing it glow and the far ones fade into haze.
- Add an anamorphic mode with a long horizontal blue streak through the sun.
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 computing ghost positions from a real lens prescription with 2x2 ray matrices, coating colors from thin-film interference, or dust on the front element lit by the sun.