Visualizations
195 / 500

195 · Retro

Sprite Stacking

A cozy pixel town where every house, car and tree is a pile of flat slices.

Every object here is a stack of flat pixel images, one per layer of height, baked from tiny voxel functions in code. To draw one, each slice is rotated by the same angle and placed one pixel above the last; the edges of the lower slices peek out underneath and read as walls, so the whole town turns with the camera and keeps its volume with no 3D math at all. Shading is baked per voxel (open tops bright, walls darker, occlusion toward the ground), and shadows are the same slices drawn as black silhouettes on the ground, each pushed further along the sun direction by its height, which is a true parallel projection. Night retints the slice sheets by the ambient light while windows, lamps and headlights keep emissive colors, and everything renders at about 320 x 200 before being scaled up with hard pixels.

Try it. Drive the red car with the arrow keys or WASD, or hold the pointer down to drive toward it. Drag to orbit and tilt the camera, Q and E rotate it, click any object to see its slices in the inspector, and press Exploded view (X) to pull its layers apart. The slider and T change the time of day; F toggles the follow camera.

  • Sprite stacking
  • Voxel slicing
  • Projected slice shadows
  • Painter's algorithm

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 sprite stacking demo, the pixel art trick that makes flat images look 3D, 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:
- Render into a small offscreen canvas (about 320 x 200) and draw it scaled up to fill the window with imageSmoothingEnabled = false, so pixels stay crisp.
- Describe a model as a voxel function f(x, y, z) that returns a color or nothing, for example a 14 x 8 x 6 car: wheels at the bottom, a body, a cabin with windows on top.
- Bake it into slices: for each z, paint a w x d image of that layer and store all the layers in one tall canvas.
- To draw the model at a position and angle, loop z from 0 up: translate to the position minus z pixels vertically, rotate by the angle, and draw slice z centered. The edges of the lower slices peek out and read as walls.
- Rotate the angle with the arrow keys and watch the car turn in 3D.

Once that works, make it beautiful:
- Shade while baking: a voxel with nothing above it is a top and stays bright, the rest are walls and get darker.
- Add a house, a tree and a few more models, place many of them on a grass and road ground image, rotate the whole world around the camera, and sort objects by their screen y each frame so nearer ones draw last.
- Draw shadows by painting each slice as a black silhouette on the ground, shifted along the sun direction by its height, into a separate layer that you composite at partial opacity.

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 drivable car with a follow camera, a day and night cycle with glowing windows, or an exploded view that pulls the slices apart.
PreviousSOFAR ChannelSound rays bend into the ocean's deep channel, lighting up caustics and shadow zones. Nextt-SNE Constellations2,000 glyph images in 196 dimensions flow into constellations under live t-SNE.

Related visualizations

  • Voxel Diorama3D A floating voxel island with baked AO, sun shadows and a waterfall. Click to build.
  • Voxel SpaceRetro Fly low over a mountain valley with the 1992 Comanche terrain trick.
  • Pseudo 3D RoadRetro A sunset coastal highway faked the 80s arcade way, from flat segments and sprites.
  • Shadow Sculpture3D One carved object casts three different shadows at once. Draw your own.
  • Mode 7 TrackRetro The per-scanline floor trick of 16-bit kart racers, with a debug view of every row.
  • Wobbly PolygonsRetro A 1990s console renderer that builds every famous glitch on purpose, toggle by toggle.
  • Vector BallsRetro 512 chrome spheres, depth sorted, morphing from a torus knot to DNA to a smiling face.
  • Sector EngineRetro A 2.5D portal engine in the mid-90s style: a slow walk round a castle at golden hour.
  • RaycasterRetro A Wolfenstein-style 3D maze drawn one column at a time.

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

← More from Emergent Mind Labs