Visualizations
470 / 500

470 · 3D

Impossible Rooms

A house that cannot exist: a ballroom in a wardrobe, a corridor longer inside than out.

A first-person walk through a small house that breaks Euclidean space. A wardrobe in the foyer opens onto a ballroom bigger than the house, the corridor to the garden room is 16 m long between doors 4 m apart, the doors on opposite sides of the hall both open onto the same study, so looking through one shows an endless tunnel of hall, study, hall, and the loop room north of the foyer must be walked around four times before you are back where you began. It is a sector and portal renderer in the style of the mid-90s engines, with one change: a portal can carry a rotation and translation. Each screen column keeps a clip window; a wall is drawn where an edge is solid, and where it is a portal the camera itself is moved by the portal's transform and the linked sector is drawn through just that opening, recursively, with sprites clipped to the sector visit they belong to. The plan in the corner draws every room where it is actually stored, so it overlaps itself exactly where the house is impossible.

Try it. Walk with WASD or the arrow keys (Q and E turn), or drag on the view: up and down walks, left and right turns. M shows or hides the floor plan and V colors every clip window by portal depth. Left alone, it gives a tour.

  • Portal rendering with transforms
  • Recursive column clipping
  • Non-Euclidean space
  • Perspective-correct texturing

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 tiny non-Euclidean house you can walk through, 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, as a portal renderer:
- Make a canvas that fills the window and resizes with it. Render into a small offscreen canvas (about 320 pixels wide) and scale it up.
- Describe the world as a few convex rooms ("sectors"): each is a list of 2D corner points, a floor height and a ceiling height. Each edge is either a solid wall or a portal into another sector.
- Render column by column. Keep a top and bottom clip limit for every screen column. Starting in the player's sector, project each edge to a range of screen columns; for each column, draw ceiling above and floor below in flat colors, and either a wall (solid edge) or, for a portal, recurse into the neighbor sector through just those columns with the clip limits narrowed to the opening.
- Walk with WASD: move the player, block solid walls, and switch sectors when crossing a portal.

Then make it impossible:
- Let a portal carry a transform: a rotation and translation that maps its edge onto an edge of another sector anywhere in the world. When recursing through it, move the camera position and facing by that transform before drawing the far sector. When the player walks through it, apply the same transform to them.
- Use that to build a corridor that is much longer inside than the gap between its two doors, and a small box whose door opens onto a big room.
- Draw a small top-down plan of every sector where it is stored, so it visibly overlaps itself, with the player's dot jumping when they cross a transformed portal.
- Darken with distance so views through portals feel deep.

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 room you must circle several times to get back, textured walls with perspective-correct mapping, or sprites clipped to the portal they are seen through.
PreviousMusic BoxA pinned brass drum plucks cantilever tines from a punched strip you can edit. NextSeed DispersalSamaras autorotate, dandelion seeds parachute and leaves flutter across a gusty meadow.

Related visualizations

  • Sector EngineRetro A 2.5D portal engine in the mid-90s style: a slow walk round a castle at golden hour.
  • Ames RoomIllusions Identical twins become a giant and a child inside a room that only looks square.
  • Infinity Mirror3D A mirrored room of neon and glowing orbs, reflected into an endless kaleidoscope.
  • Interior Mapping3D A night skyline of thousands of furnished, lit rooms, and not one of them has geometry.
  • Impossible ArchitectureIllusions Walkers climb Penrose stairs forever on a pastel tower whose paths only meet on screen.
  • Hyperbolic MazeGames A labyrinth in negatively curved space: the world glides past while you stay at the center.
  • Roguelike ExplorerRetro An amber-terminal dungeon crawl that explores itself, cat in tow, by rolling down a Dijkstra map.
  • Gyroid Caves3D Fly through glassy minimal surface labyrinths, with a second maze behind every wall.
  • Rubik's Cube3D A 3D cube that scrambles itself and then solves itself, layer by layer.

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

← More from Emergent Mind Labs