Visualizations
046 / 500

046 · Algorithms

Route Planner

Dijkstra, A*, bidirectional search and contraction hierarchies race on a printed atlas.

A countryside of about nine thousand road junctions is generated from noise: hillshaded relief with contour lines, lakes with ripple shorelines, a river with a handful of bridges, woods, towns, and highways and main roads routed between the towns by A* over the terrain. Four panels search the same map for the fastest route, each settled node bleeding into the paper as a watercolor wash with pooled edges and drying rings. Dijkstra grows a ball of equal travel time, A* leans toward the goal using a lower bound on the time left, and bidirectional Dijkstra grows two smaller balls that meet. The contraction hierarchy is built while the map prints (nodes contracted least important first, with witness searches deciding which shortcuts to add), so its query only climbs upward from both ends, settles a few dozen nodes where Dijkstra settles thousands, and unpacks its shortcuts recursively into the red route.

Try it. Drag the start or destination pin in any panel and all four routes update live, then race again when you let go. Click the map to move the destination (shift-click or right-click for the start). Press H to switch the A* heuristic between straight line, landmarks (ALT) and an inadmissible x2.5 straight line that can return a longer route, Space to rerun the race, S to swap the pins and N for a new map.

  • Contraction hierarchies with witness search and shortcut unpacking
  • A* with landmark (ALT) and straight-line heuristics
  • Bidirectional Dijkstra
  • Procedural cartography with marching-squares contours
  • Watercolor wash from a per-cell pigment field

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 route planner that races shortest-path algorithms on a generated map, with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it a cream paper color.
- Build a road network: a grid of nodes about 10 pixels apart, each nudged by a small random offset, joined to their right and lower neighbors. Drop about 20% of the links so the roads look rural.
- Pick a few random nodes as towns and connect them with fast highways (find a path along the grid and mark those links as highways). Each link's weight is its length divided by its speed.
- Draw back roads as thin gray lines and highways as thick orange lines with a dark outline.
- Implement Dijkstra's algorithm with a binary heap, from a start pin to a goal pin. Record the order in which nodes are settled.
- Animate the search by revealing a few more settled nodes every frame as soft translucent blue dots, then draw the final route as a thick red line.

Once that works, make it beautiful:
- Add A* with a straight-line heuristic (distance divided by the highway speed, so it never overestimates), and show both searches side by side on two copies of the map, advancing at the same rate.
- Display how many nodes each one settled.
- Make the frontier look like watercolor: paint the settled nodes into a low-resolution offscreen canvas with soft circles, and draw it over the map with globalCompositeOperation set to multiply.
- Let me drag the start and goal pins and rerun the race on release.

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 bidirectional Dijkstra, landmark (ALT) heuristics, or a contraction hierarchy that answers queries by settling only a few dozen nodes.
PreviousVideo FeedbackA virtual camera films its own monitor and grows spirals, tunnels and fractals. NextKnittingPixel art becomes Fair Isle knitting, stitch by twisted stitch, live on the needle.

Related visualizations

  • Crowd Flow FieldsSimulation Two armies of 3,600 units pour across a river map, steered by one Dijkstra each.
  • Roguelike ExplorerRetro An amber-terminal dungeon crawl that explores itself, cat in tow, by rolling down a Dijkstra map.
  • Maze SolverAlgorithms A maze carves itself, then A* hunts for the way out.
  • Invented AtlasGenerative art A parchment map of a world that never was, with rivers, realms and its own language.
  • Gridlock SolverAlgorithms Map every position of a sliding-car puzzle, solve it, and generate harder ones.
  • Blocks World PlannerAlgorithms A robot arm plans with A* over STRIPS states, then stacks the blocks to match your goal.
  • RRT* ParkingAlgorithms A self-driving car grows a tree of curved manoeuvres, then reverses into its spot.
  • Perfect SnakeAlgorithms A snake AI that can never crash, cutting safe shortcuts until it fills every cell.
  • Max Flow WaterworksAlgorithms Water fills a hand-drawn pipe network until the minimum cut lights up in red.

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

← More from Emergent Mind Labs