Light lab
Neon 2D raytracing: mirrors, prisms, lenses and a black hole bending light into geometric art.
Level editor
The numbers
How it works
Each ray is a start point and a direction. The tracer finds the nearest thing it hits, draws a line to it, then decides what light does there and calls itself again with the new ray. That is the recursion: one call per bounce, nested, until the light escapes, is absorbed, or reaches the bounce limit you set.
A mirror reflects: flip the part of the direction that points into the surface. Glass refracts: Snell's law bends the ray, and a little light also reflects (Fresnel), so one call can branch into two. Past the critical angle nothing gets out and the light is trapped: total internal reflection.
White light is seven rays here. Glass has a slightly higher index for violet than for red, so each colour bends a different amount and a prism fans them into a rainbow. The black hole has no surfaces at all: rays are stepped forward in small moves while gravity turns them, and anything that passes too close is swallowed.
The puzzles come in three packs, and the editor lets you build your own: place a source, mirrors, prisms, walls, splitters, stars and black holes, and mark each mirror or prism as turnable or fixed. Check first tries a coarse grid of whole-degree angles for the turnable pieces, scoring each try by how far the light misses each star. The closest misses are then refined: nudge one piece a step each way, keep any move that brings the beam closer, halve the step when nothing helps. If that fails it shifts the grid and halves its step, down to every whole degree, in small slices so the page never stalls, for up to 20 seconds. Every built-in level passed it, and it also warns if a level starts solved. Share packs the whole level into a few hundred characters after the # in the link, so nothing is stored anywhere but the link itself.
four lines of maths and one function calling itself paint every pattern on this page.