Labyrinthine
A no-dependency library that generates all the mazes you need.
Installation
pip install labyrinthine
Usage
import matplotlib.pyplot as plt
import numpy as np
from labyrinthine import depth_first
maze = depth_first(size=(31, 21))
plt.imshow(np.pad(maze, 1, constant_values=1))
plt.savefig("maze.png", bbox_inches="tight", pad_inches=0)
Parameters
depth_first
accepts the following parameters:
-
size
: either a pair ofint
specifying width and height of the maze, or a singleint
for a square one. -
start
: a pair ofint
defining the starting point. Default is the top-left corner with coordinates(0, 0)
.
The output is an integer matrix of the requested size, where 1 represents a filled cell, thus a wall, and 0 represents an empty cell, thus a passage.
⚠️ HEADS UP!Due to the nature of the algorithm, it is warmly recommended to use odd width and height values, so that the resulting matrix doesn't have a vertical and horizontal border entirely filled with walls.
Development
This repository contains a handy Makefile
to clean
, install
and uninstall
the
package in your local environment.