Build log · Simulations & Toys
How I built Tiny SF
An isometric pixel-art San Francisco built from OpenStreetMap, with live traffic

1.Why I built it
Tiny SF is San Francisco as a small isometric pixel-art city you can drag around. Every building, street, park, pier and the coastline comes from OpenStreetMap, with real heights, roof shapes, courtyards and building parts.
I wanted it to feel alive, so it also has a traffic layer on the real street and rail network, with cars, robotaxis, Muni buses, streetcars, trains, ferries, sailboats and pedestrians, plus Karl the Fog, a night mode and a Guess the Landmark game.
2.How it works
Packing OpenStreetMap into one binary
scripts/build-tinysf.mjs streams a gzipped OSM XML extract line by line. Nodes are stored in typed arrays sorted by id and found with binary search, which is far lighter than a Map for millions of nodes. Ways become buildings, areas, lines or trees, multipolygon relations are stitched from member ways, and geometry is simplified with Douglas-Peucker.
Heights come from height, or building:levels * 3.3 + 1 when only levels are tagged. A building covered by building:part ways is drawn through its parts only, each with its own min_height, roof shape and roof height. The output, public/data/tinysf.bin, stores coordinates in 0.5 m units as delta-encoded zigzag varints behind a TSF3 magic header, and the client decodes it with a DataView.
Extruding footprints with real roofs
buildings.ts extrudes each footprint into walls and a roof. Roofs are a height field in the footprint's oriented frame, with the ridge along the longest edge, which covers gabled, hipped, pyramidal, skillion and domed shapes. Courtyard holes are kept, and winding is normalised with a signed-area check.
To keep draw calls down, buildings are grouped into 900 m chunks and each chunk becomes one mesh with vertex positions stored as rounded integers relative to the chunk centre. Colours come from per-class palettes, and walls facing south-west are lit brighter for a fixed iso sun.
Rendering small to look like pixel art
The scene renders through an orthographic camera at a 30 degree elevation into a low-resolution WebGLRenderTarget with nearest filtering, then a full-screen post shader upscales it. The post pass runs a Laplacian on the depth buffer and darkens pixels where depth changes sharply, which draws outlines on building edges, then quantises colour to 24 levels per channel so shading falls into clean bands.
Fog is fractal value noise in the post shader, anchored to map coordinates and drifting in from the ocean. At night the building shader lights windows by hash: each building gets an occupancy value, whole floors can work late, and lit windows pick from a few warm and cool tints. Facade, roof, terrain and tree textures are small atlases made by scripts/generate-tinysf-sprites.mjs with gpt-image.
Traffic on the real street graph
city.ts turns road lines into paths and builds a graph keyed by endpoint. Each vehicle is a path index, a distance along it and a direction in typed arrays. advance() moves it along, and at the end of a path it hops to a random connected path or turns around at a dead end. Vehicles are spawned on roads chosen with probability proportional to length, using a cumulative-length binary search, and the count is road length over 60 m, capped at 9,000.
Speeds depend on road class, buses run at 80%, and trains use the same advance() on the rail graph. Vehicles, parked cars and billboards are instanced meshes built from boxes with a per-vertex kind so headlights and tail lights can glow at night.
Guess the Landmark
The game picks five landmarks at random. You click where you think each one is, the click is raycast onto the ground plane, and you score max(0, 1000 - distance / 3) points, so anything within 3 km earns something. The map then flies to the real spot and drops a pin. Clicking a building outside the game shows its class, height, estimated floors, roof shape and footprint area.
3.Try it
Drag to pan, scroll to zoom, Q and E to rotate, N for night, click a building for details.


