Prompt Claude Code Claude Opus 4.8 Let's create a doodle of traffic flow. The simulator is a top-down view of a road network. The network includes procedurally-generated roads with various characteristics including speed, lane count, and numerous intersection types such as stop signs, traffic lights with and without turn lanes, round-abouts, etc. The simulator should show individual agents with acceleration/braking rules that lead to emergent behaviors like traffic jams. There can be macro-level details that fluctuate over time with the simulation, like a simulated day/night cycle and the corresponding rush hours that have higher levels of traffic impacting the system.
Let's create a doodle of traffic flow. The simulator is a top-down view of a road network. The network includes procedurally-generated roads with various characteristics including speed, lane count, and numerous intersection types such as stop signs, traffic lights with and without turn lanes, round-abouts, etc. The simulator should show individual agents with acceleration/braking rules that lead to emergent behaviors like traffic jams. There can be macro-level details that fluctuate over time with the simulation, like a simulated day/night cycle and the corresponding rush hours that have higher levels of traffic impacting the system.
Nobody in this city is steering toward a jam, yet jams keep happening. That's the whole point. Every car is running the same myopic rule — keep a safe distance, don't exceed the limit, ease off when the car ahead does — and traffic jams, stop-and-go shockwaves, and gridlocked intersections all fall out of that rule colliding with finite road space.
The car-following rule
Each vehicle is an independent agent governed by the Intelligent Driver Model, the workhorse of microscopic traffic simulation. On every frame a car computes its acceleration from just three things it can "see": its own speed, the gap to the car ahead, and how fast that gap is closing.
A road network that builds itself
Hit 🗺️ New map and the city is regenerated from scratch on a jittered grid, then pruned (while staying connected) so it never looks like perfect graph paper. Roads come in a hierarchy:
Cars are born at the edges of the map, get a shortest-time route to a random exit (a tiny Dijkstra search that prefers arterials and penalizes slow intersections — so the main roads naturally carry more load), and change lanes to line up for their next turn. When they reach the far edge, they leave.
Five kinds of intersection, one set of rules
The hard part of any traffic sim is the intersection, and this one generates a realistic mix and controls them all through a single "may I enter the conflict zone?" question:
Don't like what the city did? Grab the 🚦 Junction tool and click any intersection to cycle it between a light, a stop, a two-way, and a roundabout — the geometry rebuilds live and you can watch the same demand behave completely differently.
The day has a rhythm
A clock runs overhead. Demand isn't constant — it follows a commuter curve with a morning peak around 8am and a heavier evening peak around 5:30pm, a quiet midday lull, and a near-empty overnight. Leave rush hours on and just watch: the arterials load up, the lights start backing up, the congestion meter climbs, and then the city exhales. A day/night cycle dims the world and flips on headlights and tail-lights after dark. (Prefer to drive the load yourself? Turn rush hours off and take the Demand slider.)
Things to try
Controls up top tune Sim speed, Clock speed, and Demand;
Spacepauses,Rregenerates, and keys1–3pick a tool. Everything is one self-contained file — no build, no dependencies, just a canvas and the rules.