Visualizations
431 / 500

431 · 3D

Infinity Mirror

A mirrored room of neon and glowing orbs, reflected into an endless kaleidoscope.

A dark room with mirror walls, a mirror ceiling and a floor of black water, hung with fairy light strands, glowing orbs and a precessing neon ring. Because the walls are vertical, the reflections split in two: the floor and ceiling stack copies of the room above and below, while the walls are handled by recursive beam tracing, where every mirror seen through the view window spawns a reflected copy of the room seen through a narrower window, each bounce a little dimmer and greener, until the beam is too thin or too dark to matter. Every light is then projected once per beam and per level, tens of thousands of images per frame, with near ones drawn as glow sprites and far ones splatted into a float buffer that is tone mapped and bloomed. When every corner angle is 180/n degrees the copies tile the plane and the reflections form a wallpaper group, *333, *442, *632 or *2222; a hexagonal room or a bent mirror breaks that symmetry, and the plan in the corner shows every reflected room the beams passed through.

Try it. Drag to look around, or drag an orb to move it. WASD walks and the left and right arrows turn. Pick a room shape with the chips or keys 1 to 5, press [ and ] to bend a mirror off its kaleidoscopic angle (0 straightens it), M toggles the plan and Space pauses the orbs. Left alone, it slowly turns and morphs between rooms.

  • Recursive beam tracing
  • Reflection groups
  • Additive splatting and bloom
  • Unfolded mirror geometry

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 an infinity mirror room 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, in 2D from above:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it near black.
- Draw an equilateral triangle in the middle of the screen: three mirror walls. Put a few colored glowing dots inside it, and a viewer point.
- Use the trick of unfolding: a reflection in a mirror looks exactly like a copy of the room reflected across that mirror. Write a function that reflects a point across a line, then recursively build reflected copies of the triangle (reflect the whole room across each wall, then each copy across its own walls) to a depth of about 6. Draw every copy's outline and its dots, dimmer with each reflection.
- Because the triangle's angles are 60 degrees (180/3), the copies tile the plane perfectly. That tiling is a kaleidoscope.

Then go first person:
- Give the viewer a heading and a field of view. For each copy, project each dot to a screen x from its angle relative to the heading and a size from its distance, and draw it as a soft glowing circle with globalCompositeOperation = "lighter".
- Treat the floor and ceiling as two more parallel mirrors: draw each dot again at heights reflected above and below the room, dimmer each time.
- Multiply each reflection's color by a slightly green tint (about 0.85, 0.95, 0.9), like real mirror glass, so the far copies fade into green.
- Let the mouse turn the viewer and the arrow keys walk.

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 square and 30-60-90 rooms that tile differently, a hexagonal room that does not, or clipping each copy to the part of the view its mirror actually covers (beam tracing).
PreviousWind WalkerA six-legged beach machine walks on Theo Jansen's eleven-bar linkage. NextKirkwood GapsThousands of asteroids and Jupiter's resonances carving gaps into a featureless belt.

Related visualizations

  • Anamorphic MirrorIllusions A wildly warped drawing that a chrome cylinder turns back into a picture.
  • Interior Mapping3D A night skyline of thousands of furnished, lit rooms, and not one of them has geometry.
  • Impossible Rooms3D A house that cannot exist: a ballroom in a wardrobe, a corridor longer inside than out.
  • Ames RoomIllusions Identical twins become a giant and a child inside a room that only looks square.
  • Ambiguous ObjectsIllusions Paper tubes that look round on the table and square in the mirror behind them.
  • Prism PuzzleGames Split white light with rutile prisms to light colored targets. A search AI plays.
  • Wythoff Kaleidoscope3D One draggable seed in a mirror triangle generates every convex uniform polyhedron.
  • Room EchoesSound Clap in a room on a blueprint and hear its exact echoes, from bathroom to cathedral.
  • Wallpaper GroupsGenerative art Paint once and any of the 17 plane symmetry groups repeats the stroke across the plane.

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

← More from Emergent Mind Labs