aldus.nexus

Light lab

Neon 2D raytracing: mirrors, prisms, lenses and a black hole bending light into geometric art.

The numbers

bounce histogramray segments at each depth
intensity decayshare of the light still going
the recursion, first ray

    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.

    r = d - 2 (d ยท n) nreflection: d in, r out, n the unit normal
    n1 sin θ1 = n2 sin θ2Snell's law at a glass surface
    n(λ) = A + B / λ²Cauchy dispersion: shorter wavelengths bend more
    a = -1.5 rs L² r / |r|5light bending near a black hole, L = |r × v|
    miss = Σ max(0, dmin - r)puzzle check score: closest approach of the light to each star, 0 when solved