Visualizations
357 / 500

357 · Games

Prism Puzzle

Split white light with rutile prisms to light colored targets. A search AI plays.

The beam is twelve thin rays, one per wavelength, traced with exact geometry. Mirrors reflect, splitters send half each way, crown glass prisms turn the beam by total internal reflection, and 30 degree rutile wedges refract it with rutile's measured dispersion, six times diamond's, so white light fans into a wide spectrum. A target only lights when most of what reaches it is its own color, so the rainbow is the mechanic. Levels are generated from a seed: pieces are placed on the beam, targets go where nearly pure colors land, walls fill cells the light never crosses, and the pieces go back in your tray. In attract mode a beam search solver plays, trying every piece and rotation on the cells the light touches and keeping the boards whose colors come closest to their targets. The attract loop opens on a later three-target level, where one fan lights red, green and blue at once.

Try it. Drag pieces from the tray onto the table, click a piece to rotate it (right-click or Shift-click turns it back) and drag it off the table to return it. Press Solve or the space bar to watch the solver search, Reset or R to clear the board, and Next or N for a new level. Your own game starts at level 1, and levels never run out.

  • Spectral ray tracing
  • Procedural level generation
  • Beam search solver

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a light puzzle game 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 and stays sharp on high-DPI screens. Draw a dark 10 by 7 grid as the table, a light source on the left edge, a few wall blocks and one round target.
- Let the player drag mirrors from a tray onto empty cells and click them to rotate in 22.5 degree steps.
- Trace the beam every time the board changes: march a ray from the source, find the nearest mirror segment, wall or target it hits, reflect off mirrors, and stop at walls. Draw the path as a glowing line. Light the target when the beam reaches it, and show a little celebration when every target is lit.

Once that works, make it beautiful:
- Trace the beam as about 12 separate wavelengths, each with its own color. Add a triangular prism piece that refracts with Snell's law and an index that rises toward blue (a Cauchy formula is fine), so white light fans into a spectrum.
- Give targets colors, and only light a red target when the light reaching it is mostly red. Now the spectrum is the puzzle.
- Draw the light with globalCompositeOperation = "lighter" and a blurred glow pass.
- Write a few levels by placing pieces yourself, tracing, and putting targets where pure colors land.

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 beam splitters and color filters, generating endless levels, or a solver that searches for the answer.
PreviousMountain Wave CloudsWind over a range rings into lee waves, and saucer clouds stack at the crests. NextOptical BenchA blueprint ray tracer: prisms, lenses, mirrors and a fiber with real glass dispersion.

Related visualizations

  • Infinity Mirror3D A mirrored room of neon and glowing orbs, reflected into an endless kaleidoscope.
  • Rainbow OpticsPhysics A double rainbow, dark band and fogbow computed from Snell's law and wave optics.
  • Ice Crystal HalosPhysics Sundogs, arcs and halos built up live from millions of rays traced through ice.
  • Bubble Bank ShooterGames A pastel bubble shooter whose AI traces 640 bank shots before every throw.
  • Light & ShadowPhysics Red, green and blue lights cast crisp, colored shadows through spinning shapes.
  • Sliding Puzzle SolverGames IDA* with pattern databases solves the 15-puzzle in the fewest possible moves.
  • Marble LabyrinthGames A wooden tilt maze where a careful AI steers a steel ball between the holes.
  • Lights Out AlgebraMath The toggle-tile puzzle solved instantly at any size by linear algebra over GF(2).
  • Sokoban ForgeAlgorithms Crate puzzles forged by playing backward from the goals, then solved by A*.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs