Skip to main content
100%

Prim’s Algorithm II

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on May 8, 2014

This example generates a maze using Prim’s algorithm and floods it with color to visualize Manhattan distance from the starting cell. As the animation progresses, a hue-changing fill pulses over frontier cells, highlighting the maze’s structure and growth pattern. The maze is drawn to a Canvas 2D context, with each cell and connecting wall filled via `fillRect`. The implementation uses D3 v3’s `d3.timer` for animation and `d3.hsl` for color encoding, while the maze generation relies on a custom binary heap for priority-based frontier expansion.

AI-generated description

This maze is generated using Prim’s algorithm and then flooded with color. Hue encodes Manhattan distance from the starting cell. (This is not an optimal visual encoding, but it suffices and is pretty.)

Color is useful to visually compare the structure of mazes; without color, the black and white alternating cells are too noisy to offer any pre-attentive comparisons. Compare a maze generated by Prim’s algorithm to random traversal, randomized depth-first traversal and Wilson’s algorithm.

See this color flood applied directly to the pixel grid.

gpl-3.0 Licensed

Similar vizzes