Back to Projects
experimentJuly 8, 2026
DFS Maze Generation
This project is a procedural maze generator built with p5.js using Depth-First Search (DFS) and an iterative version of the recursive backtracking algorithm. Starting from the top-left cell, the algorithm randomly explores unvisited neighboring cells, removes walls to create paths, and uses a stack to backtrack whenever it reaches a dead end. This continues until every cell has been visited, producing a perfect maze with exactly one path between any two cells. The project also includes adjustable generation speed, optional visited-cell visualization, current-cell highlighting, and the ability to automatically save the completed maze as a PNG image.