Skip to main content
100%

Randomized Depth-First II

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

A maze is generated using randomized depth-first traversal, then flooded with color to reveal its structure. Hue encodes the Manhattan distance from the starting cell, making the maze’s branching patterns visually comparable. The animation is rendered on a Canvas 2D context, drawing cells and passages incrementally as the flood expands. The code uses D3’s `d3.timer` to drive the animation loop and `d3.hsl` to cycle hue over time, while a custom `generateMaze` function builds the maze and `fillRect` calls paint each cell and connecting corridor.

AI-generated description

This maze is generated using randomized depth-first traversal 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 randomized depth-first traversal to random traversal, Prim’s algorithm, and Wilson’s algorithm.

See this color flood applied directly to the pixel grid.

gpl-3.0 Licensed

Similar vizzes