Procedural maze generator for Typst with customizable start and finish cells.
This package generates and renders rectangular mazes using a deterministic random generator. The maze layout is created with a depth-first search (DFS) backtracking algorithm, producing a perfect maze (exactly one path between any two cells).
Installation
#import "@preview/mazed:0.1.0": maze
Examples
Basic maze
#maze(
12,
8,
width: 10cm
)
Red maze with given seed, as well as start and finish markers
#maze(
10,
10,
width: 10cm,
seed: 123,
start: [🚩],
finish: [🏁],
stroke: red
)
Function
maze
Generates and renders a maze.
maze(
cols,
rows,
width: 100%,
height: 100%,
seed: 0,
stroke: auto,
start: none,
finish: none,
)
Parameters
cols- number of maze columnsrows- number of maze rowswidth- width of the rendered mazeheight- height of the rendered mazeseed- random seed for deterministic generationstroke- how to stroke the mazestart- content placed in the start cellfinish- content placed in the finish cell
Returns: Content containing the rendered maze.
Algorithm
The maze is generated using a depth-first search (DFS) backtracking algorithm, producing a perfect maze. The seed ensures deterministic generation: the same parameters always produce the same maze.