Visualizations
284 / 500

284 · Retro

Raycaster

A Wolfenstein-style 3D maze drawn one column at a time.

There is no 3D engine here. For each column of pixels the program casts a ray across a flat 2D grid map using the DDA algorithm, finds the first wall it hits, and draws a vertical strip whose height falls off with distance. Procedurally generated wall textures, distance fog and a floor gradient make the corridors feel solid. A minimap shows the rays fanning out from the player.

Try it. Drag on the view to walk and turn (up and down to walk, left and right to turn), or click it and use the arrow keys or WASD. Leave it alone and it explores on its own.

  • DDA ray casting
  • Texture mapping with drawImage strips
  • Floor casting with ImageData

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 Wolfenstein-style 3D maze with a raycaster, using 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, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window.
- Describe the maze as a 2D grid of numbers (0 = empty, 1-4 = wall types), about 16x16, with a solid border.
- Keep a player position (x, y in grid units), a direction vector, and a camera plane vector perpendicular to it (length about 0.66, which gives a 66 degree field of view).
- For each screen column, cast a ray with the DDA algorithm: step from grid line to grid line until you hit a wall, then use the perpendicular distance (straight-line distance causes fisheye) to draw a vertical strip whose height is screenHeight / distance.
- Color walls by type, with y-side hits darker so corners read clearly.
- Paint ceiling and floor as gradients. Walk with the arrow keys or WASD, without passing through walls.

Once that works, make it beautiful:
- Generate 64x64 wall textures (bricks, stone, wood planks) into offscreen canvases at load, and draw each column as a 1-pixel-wide slice with drawImage(texture, texX, 0, 1, 64, x, top, 1, height).
- Add distance fog that blends walls toward a dark color, and a minimap in the corner showing the rays fanning out from the player.
- Add an autopilot that explores on its own when nobody is pressing keys.

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 textured floor casting, billboard sprites with a depth buffer, or doors that slide open.
PreviousFlow FieldThousands of particles ride an evolving noise field into silky trails. NextLottery TicketPrune a network to a sparse winning ticket that still learns, round by round.

Related visualizations

  • Sector EngineRetro A 2.5D portal engine in the mid-90s style: a slow walk round a castle at golden hour.
  • Roguelike ExplorerRetro An amber-terminal dungeon crawl that explores itself, cat in tow, by rolling down a Dijkstra map.
  • Wobbly PolygonsRetro A 1990s console renderer that builds every famous glitch on purpose, toggle by toggle.
  • Mode 7 TrackRetro The per-scanline floor trick of 16-bit kart racers, with a debug view of every row.
  • Sprite StackingRetro A cozy pixel town where every house, car and tree is a pile of flat slices.
  • Voxel SpaceRetro Fly low over a mountain valley with the 1992 Comanche terrain trick.
  • Anamorphic Chalk3D Pavement chalk that snaps into a chasm, a stairway or floating cubes from one spot.
  • Hidden 3DIllusions A live magic eye picture: a turning 3D sculpture hidden in colorful noise.
  • MandelbulbFractals A 3D fractal, ray marched pixel by pixel on the CPU.

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

← More from Emergent Mind Labs