Feature Library

Road network, lane graph and traffic

0.31 CPU ms
A still of the Road network, lane graph and traffic demo
Still
The live demo starts when it’s in view.Tap a car to follow it · [ and ] pick a car · Space pauses

Roads as plain data (nodes, edges drawn through bends and rounded to arcs, a type on each) laid out into junctions with kerb returns and setbacks, then…

What it costs a frame

0.31 ms
GPU
not used
CPU, median
0.31 ms
CPU, 95th pct
0.48 ms
Draw calls
0
Weight
Light

Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.29–0.34 ms). What ran: Measured running at 20 new cars a minute on each road in (about 100 cars at once): every car decides and moves every 1/20 s of simulated time, and the frame includes the Canvas 2D drawing of the cars, lights and overlays over a cached road layer. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring toolnot timed0.310.48
apple · Apple A19 Proin a browser tab · 16 November 2026not timed0.681.36
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026not timed0.500.89

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
Canvas 2DA 2D canvas: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages

What it’s for

  1. Town traffic in a game, a city builder or a toy
  2. NPC drivers that stop at lights and give way
  3. Turning a drawn road network into drivable lanes
  4. Route guidance on a map: the quickest drive, keeping to the lanes
  5. Teaching junction rules and traffic flow

Pitfalls, in brief

  1. Arms at a junction are sorted by heading, and the straightest pair is the road through: it has priority (or signal group A).
  2. Traffic drives on the right.
  3. A road too short for its junctions’ setbacks gets no lanes and a warning, and the graph may then have unreachable lanes or traps: always show graph.warnings while editing.
  4. Rebuild the lane graph (and the traffic) when the network changes; path ids are made from edge and node ids, so a car can be carried over only if its path still exists.
  5. Cars are distances along paths, not bodies: two connectors that cross are kept apart by the give-way and conflict rules, not by collision.
4 more in brief
  1. Without a signal model, signalled arms still have their lines, but nobody stops for red: pass signals: signalModel(graph) to TrafficSim.
  2. step(dt) runs whole steps of 1/20 s (TRAFFIC_STEP) and keeps the rest of dt for the next call, so the same seed gives the same traffic at any frame rate; pose(car) looks ahead by that rest, so cars glide.
  3. A busy town fills its roads into rings of queues, each waiting on the next.
  4. Coordinates are metres on the ground plane, x and z (y up).
9 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Treiber, Hennecke and Helbing, the Intelligent Driver Model (2000): Car following: the desired gap s0 + vT + v·Δv / 2√(ab) and the acceleration a[1 − (v/v0)⁴ − (s*/s)²]. The published model, not code.

Dijkstra’s shortest paths (1959): Routing over lane paths, with arriving at the goal as a node of its own.

George Marsaglia, xorshift generators (2003): The seeded generator behind spawning and choices.

Fowler–Noll–Vo hash (FNV-1a): Each junction’s signal offset from its id.

roadslane graphtrafficjunctionstraffic signalsgive wayright of wayroutingdijkstraintelligent driver modelcar followingsimulationdeterministiccanvas 2dno dependencies

Near it in the frame