Visualizations
269 / 500

269 · Illusions

Ames Room

Identical twins become a giant and a child inside a room that only looks square.

Every point of an ordinary rectangular room is slid along its own sight line from the peephole by a perspective collineation, X' = E + (X - E) / (1 + w . (X - E)), a projective map that fixes every ray through the eye and keeps planes flat. From the peephole the picture is identical to the rectangular room, but the real room is a skewed trapezoid whose left corner is twice as far away as its right. The room is ray cast per pixel: each ray is clipped against the six wall planes, and the hit point is mapped back through the inverse collineation so the checkerboard, wallpaper and windows are painted in rectangular coordinates. The twins are real people on the real sloped floor, so their size on screen tells the truth the room hides. Outside, the solid outline is the real room and the dashed one, with ghost figures, is what your eye reports.

Try it. Drag either twin across the floor and watch them grow and shrink. Drag the background or press P to step outside the peephole and orbit the room. Distort buttons (or [ and ]) change how skewed the room is.

  • Perspective collineation
  • Per-pixel ray casting
  • Convex polyhedron clipping
  • Procedural textures

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 Ames room illusion with JavaScript and the HTML canvas element: through a peephole two identical people look like a giant and a child in an ordinary room, and stepping outside reveals the room is warped. 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:
- Define a normal rectangular room (say 4 wide, 2.8 tall, 4.4 deep) and a peephole eye point E just in front of its front wall.
- Distort it with a perspective collineation that slides every point along its own sight line from E: X' = E + (X - E) / (1 + w . (X - E)), with w = (0.2, 0, 0). Explain in a comment why this keeps the view from E identical: every ray through E maps to itself and planes stay planes.
- Write a small perspective camera (position, look-at, project) and draw the distorted room's floor and walls as filled polygons, sorted back to front, with a checkerboard floor made of many small quads mapped through the same function.
- Put two identical stick people of the same real height in the back-left and back-right corners of the distorted floor, standing straight up, and draw them by projecting their feet and heads.
- Put the camera exactly at E: the room should look rectangular and the people very different in size.

Once that works, make it beautiful:
- Add wallpaper stripes and windows on the back wall by mapping rectangular-room points through the distortion, so they look perfectly rectangular from the peephole.
- Let the mouse drag a person along the back wall and watch them grow and shrink.
- Add a button that smoothly flies the camera out of the peephole to orbit the room and shows its true trapezoid outline.

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 ray casting the room per pixel with the inverse map for crisp textures, drawing the rectangular room your brain reports as a dashed ghost, or adding a slider for how strongly the room is skewed.
PreviousMelting CrystalNearly 2,000 atoms freeze into crystal grains, melt and boil from one pairwise force. NextCometA comet rounds the Sun and grows a straight blue ion tail and a curved dust tail.

Related visualizations

  • Impossible Rooms3D A house that cannot exist: a ballroom in a wardrobe, a corridor longer inside than out.
  • Ambiguous ObjectsIllusions Paper tubes that look round on the table and square in the mirror behind them.
  • 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.
  • Checker ShadowIllusions Squares A and B are the exact same gray. Move the light and the shadow keeps lying.
  • Anamorphic MirrorIllusions A wildly warped drawing that a chrome cylinder turns back into a picture.
  • Hidden 3DIllusions A live magic eye picture: a turning 3D sculpture hidden in colorful noise.
  • Anaglyph CathedralIllusions A sunlit gothic nave in real stereo 3D: red-cyan glasses, crossed eyes or wiggle.
  • Hyperbolic MazeGames A labyrinth in negatively curved space: the world glides past while you stay at the center.

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

← More from Emergent Mind Labs