Home▸Nature & Climate▸Rainbow Ray Tracer (2D)

Rainbow Ray Tracer (2D)

A 2D geometric-optics ray tracer: parallel sunlight rays hit a circular water-droplet cross-section, refract on entry (Snell's law), reflect once or twice inside, refract out, and disperse by wavelength — building the real 42-degree primary and 51-degree secondary rainbow angles from first principles.

Nature & Climate2DModerate60 FPS📱 Mobile-adapted💧 Water⇄ 3D version
2d-rainbow ↗ Open standalone

This 2D companion to the 3D atmospheric rainbow trades the wide sky scene for the geometry underneath it: a flat cross-section of a single spherical droplet with individual light rays traced through it one Snell's-law refraction, one or two internal reflections, and a final refraction at a time. Every ray in the fan is a genuine vector-optics computation — the seven coloured rays you see splitting apart are seven different refractive indices, each producing its own exit angle from the same entry height. The graph beside the droplet plots that exit (scattering) angle against entry height for every traced ray, and its peak at roughly 42° and dip at roughly 51° are the primary and secondary rainbow angles, discovered here the same way Descartes and Airy derived them: by tracing rays through a sphere and finding where they bunch up.

🔬 What It Demonstrates

Real vector refraction and reflection at a circular boundary, wavelength-dependent dispersion, and the minimum-deviation caustic that makes the rainbow angle bright rather than an arbitrary cutoff.

🎮 How to Use

Drag the impact-parameter slider to move a single highlighted ray across the droplet, or press Sweep to animate it. Toggle the ray fan and the secondary bow, and switch the droplet's liquid to see the angles shift.

💡 Did You Know?

The bright edge of a rainbow exists because many different entry heights all produce almost the same exit angle there — a ray-density pile-up called a caustic, the same optical effect that makes light patterns dance on a swimming-pool floor.

⚙ Under the hood

A 2D companion to the 3D atmospheric rainbow: real vector ray tracing of parallel sunlight through a circular water-droplet cross-section — Snell's-law refraction on entry, one or two internal reflections, refraction on exit — with wavelength-dependent dispersion producing the true ~42-degree primary and ~51-degree secondary rainbow angles as measured extrema of a live scattering-angle graph, not hardcoded constants.

rainbowray tracingrefractionSnell's lawdispersiongeometric opticsinternal reflection2d

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)