ASCII City build log - WordPad
✕
C:\ar9av\builds\ASCIICIT.TXT
  1. Desktop
  2. Build Log
  3. Simulations & Toys

Build log · Simulations & Toys

How I built ASCII City

An endless raycast 3D city drawn entirely in text characters on a canvas

Screenshot of ASCII City running in the portfolio
ASCII City, running on the desktop. Open it yourself →

1.Why I built it

I wanted to see whether a tiny custom engine, plain JavaScript and a canvas with no WebGL, models or shaders, could draw a whole living city in letters and symbols.

I also wanted it to be endless. The world is never stored: every cell, whether road, tower, park, river, lake or bridge, is derived from hash noise when it is needed, so you can walk forever in any direction.

2.How it works

A world made of a function

cellAt(x, y) is the whole map. Roads are a modulo test on an 11-cell block pitch with 3-cell roads. Rivers are two families of bands whose centre lines are warped by 1D value noise, and lakes are where 2D noise passes 0.76. A road over water becomes a bridge, and water cells beside a deck get gapped railing posts.

Each block is split into four quadrants at a hashed point. A quadrant is a tree park (always on a riverbank, otherwise 16% of the time) or a tower whose height depends on a noise-driven district, plus a hashed hue and a character ramp like XX## or $$§s. Results go in a Map cache that is cleared past 40,000 entries.

DDA raycasting that keeps several hits

Each character column casts one ray with a DDA grid walk. A classic raycaster stops at the first wall, but trees and bridge railings are short, so stopping there blacked out the skyline behind them. Instead the ray collects up to 10 hits and paints them far to near, and it stops early only when a hit is tall enough that its top is above the screen.

The nearest hit distance goes into a per-column z-buffer. Walls are textured procedurally: floor bands, lit windows chosen by hash, ground-floor shopfronts, signs, and masts with blinking aircraft beacons on tall towers.

Floor casting and billboards

Every row below the horizon is floor-cast back into world coordinates, and the cell under it picks a character and colour: lane markings, kerbs, zebra crossings, grass, animated water and bridge decking. Cars, pedestrians, streetlights and beacons are billboards depth-tested against the column z-buffer.

They started as solid boxes of characters. A later pass masked them into silhouettes: trees carve a trunk and ragged canopy so you see the city through gaps, cars get a glass cabin and wheels, and pedestrians were rescaled from 1.7 cells to 0.62 with a walk cycle, because at 1.7 against a 0.55 eye height they were about three times human scale.

Drawing text fast

The frame is built into flat arrays of characters and colours, then blitted by scanning each row and calling fillText once per run of same-coloured characters. Calling it once per cell would be far slower. The billboard pass reuses a pool of objects and sorts in place on a stored distance so it does not allocate every frame.

Night detail, minimap and quests

A night pass added a star field bucketed by world bearing so it stays put as you turn, a moon at a fixed bearing, streetlights every 7 cells, and city lights smeared into vertical reflections on water. Later commits added a GTA-style minimap, beacons at some intersections that point to a destination a few blocks away, and a periodic colour drift that a finished beacon quest makes permanent. No_4mat's track "1992" plays in the background with a now-playing label.

3.Try it

Autopilot walks the streets; WASD or arrows take over, M toggles the minimap, C shifts colour, H hides the HUD.

More from the build log

ASCII City · 3 min readAll 29 builds