Visualizations
106 / 500

106 · Games

Hyperbolic Maze

A labyrinth in negatively curved space: the world glides past while you stay at the center.

The rooms are the heptagons of the {7,3} tiling, three to a corner, which only fits in the hyperbolic plane; the Poincare disk shows it with rooms shrinking toward the rim, and the number of rooms within n steps grows exponentially. Each room is a 3x3 Lorentz matrix on the hyperboloid model, generated breadth-first by rotating and boosting across each edge and deduplicated by where its center lands, and a randomized depth-first spanning tree over that adjacency graph carves the maze, with extra rings of rock so the tiling never runs out. Walking from room to room glides a Lorentz camera matrix along the geodesic between the two centers, an exact isometry of the disk, so you always stay in the middle; walls are drawn as true geodesic arcs and thin with the disk's conformal factor. The autopilot floods the maze breadth-first (the bright wavefront), then follows the shortest path to the glowing gate on the rim.

Try it. Use the arrow keys or WASD to step toward the room in that direction, or tap a room: a neighbor is one step, a farther room is walked to by the maze route. Drag to turn the disk, press R for a new maze, and go idle for a few seconds to let the autopilot take over.

  • Hyperboloid model and Lorentz matrices
  • Poincare disk projection
  • Spanning tree maze
  • Breadth-first search

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 maze you walk through in the hyperbolic plane, 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 (scale by devicePixelRatio). Draw the Poincare disk as a big circle in the middle.
- Work in the hyperboloid model: a point is (x, y, t) with t^2 - x^2 - y^2 = 1, it maps into the disk as (x, y) / (1 + t), and isometries are 3x3 matrices. Write helpers for a rotation, a boost (a translation along the x axis by distance d, using cosh d and sinh d) and matrix multiply.
- Build the 7,3 tiling (seven-sided rooms, three around each corner): a heptagon has circumradius R with cosh R = cot(pi/7) cot(pi/3), and neighboring centers are 2a apart with cosh a = cos(pi/3) / sin(pi/7). Starting from one tile's matrix, make each neighbor as M * rotate(2 pi k / 7) * boost(2a) * rotate(pi), breadth-first out to about 5 rings, and skip duplicates by rounding the center coordinates into a key.
- Carve a maze with a randomized depth-first search over neighboring tiles and draw the closed edges as walls, thinner toward the rim.

Once that works, make it beautiful:
- Keep the player at the center: keep a camera matrix, and to walk to a neighbor, animate the camera with a boost along the direction of that room's center, so the whole world glides.
- Draw edges as geodesics by sampling points between the two corners on the hyperboloid and normalizing them.
- Color rooms by their breadth-first distance from you and add an autopilot that walks the shortest path to an exit on the rim.

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 a 5,4 or 8,3 tiling, an animated breadth-first wavefront, or tapping a room to walk there.
PreviousGrowing Neural CellsCells running one tiny learned rule grow a gecko from a single seed and heal its wounds. NextRayleigh-Taylor FingersHeavy ink collapses into mushroom fingers in a glass tank you can turn upside down.

Related visualizations

  • Marble LabyrinthGames A wooden tilt maze where a careful AI steers a steel ball between the holes.
  • Gyroid Caves3D Fly through glassy minimal surface labyrinths, with a second maze behind every wall.
  • Hyperbolic TilingMath An endless koi garden of {p,q} ponds tiling the Poincare disk, with fish circling.
  • Maze SolverAlgorithms A maze carves itself, then A* hunts for the way out.
  • 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.
  • Topological SnakeGames Snake on a torus, a Klein bottle and a projective plane, with the real surface turning beside it.
  • Gridlock SolverAlgorithms Map every position of a sliding-car puzzle, solve it, and generate harder ones.
  • Impossible ArchitectureIllusions Walkers climb Penrose stairs forever on a pastel tower whose paths only meet on screen.

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

← More from Emergent Mind Labs