A Python package for generating and visualizing mazes
Project description
Mazewright
A Python package for generating and visualizing perfect mazes using various algorithms.
Features
- Multiple algorithms: Recursive Backtracker, Prim's, and Kruskal's algorithms
- Multiple export formats: PNG, SVG, and ASCII art output
- Clean API: Simple, intuitive interface for maze generation
- Visualization: Built-in matplotlib rendering with customizable styling
- CLI tool: Generate mazes from the command line
- Type hints: Full type annotations for better IDE support
- Well-tested: Comprehensive test suite ensuring perfect maze generation
Installation
pip install mazewright
For development:
git clone https://github.com/sebastian-griego/Mazewright.git
cd Mazewright
pip install -e ".[dev]"
Quick Start (30 seconds)
Python API
from mazewright import generate
from mazewright.visualize import save
# Generate a 20x20 maze using Prim's algorithm
maze = generate(20, 20, algorithm="prim")
# Save to file
save(maze, "my_maze.png")
Command Line
# Generate a maze with default settings
python -m mazewright
# Customize size and algorithm
python -m mazewright --rows 30 --cols 30 --algo kruskal --out maze.png
# Export to different formats
python -m mazewright --out maze.svg # SVG (scalable vector graphics)
python -m mazewright --out maze.txt # ASCII art
python -m mazewright --format ascii # Force ASCII output
# Fine-tune appearance
python -m mazewright --rows 15 --cols 20 --cell-size 25 --wall-width 3
API Reference
Core Functions
# Generate a maze
maze = generate(rows=10, cols=10, algorithm="backtracker")
# Available algorithms:
# - "backtracker": Recursive backtracker (DFS)
# - "prim": Prim's algorithm (frontier growth)
# - "kruskal": Kruskal's algorithm (union-find)
Maze Object
from mazewright import Maze, Wall
# Create empty maze
maze = Maze(rows=10, cols=10)
# Access cells
cell = maze[0, 0]
# Check walls
if cell.has_wall(Wall.NORTH):
print("Wall to the north")
# Carve passages manually
maze.carve(0, 0, 0, 1) # Connect (0,0) to (0,1)
Visualization
from mazewright.visualize import render, save, save_svg, save_ascii
# Render to matplotlib figure
fig = render(maze, cell_size=1.0, wall_width=2.0)
# Save to PNG file
save(maze, "output.png", cell_size=20, wall_width=2, dpi=100)
# Save to SVG (scalable vector graphics)
save_svg(maze, "output.svg", cell_size=20, wall_width=2)
# Save or display as ASCII art
ascii_str = save_ascii(maze) # Returns string
save_ascii(maze, "output.txt") # Saves to file
print(ascii_str) # Display in terminal
Example Output
Running python -m mazewright --rows 15 --cols 15 --algo prim generates mazes like:
Algorithms
Recursive Backtracker
- Produces long, winding passages
- Low branching factor
- Implemented as iterative DFS for efficiency
Prim's Algorithm
- More uniform branching
- Grows from a frontier of cells
- Good balance of corridors and branches
Kruskal's Algorithm
- Most uniform distribution
- Uses union-find data structure
- Treats maze as a graph problem
Development
Setup
# Install with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Testing
pytest
Code Quality
# Format code
black mazewright tests
# Lint
ruff check mazewright tests
Architecture
mazewright/
├── __init__.py # Public API
├── maze.py # Core data structures
├── visualize.py # Rendering engine
├── algorithms/
│ ├── backtracker.py # Recursive backtracker
│ ├── prim.py # Prim's algorithm
│ └── kruskal.py # Kruskal's with union-find
└── __main__.py # CLI entry point
Future Enhancements (v0.2+)
- More algorithms: Wilson's, Aldous-Broder, Hunt-and-Kill
- Masks: Non-rectangular grids, shaped mazes
- Themes: Preset visual styles
- 3D mazes: Multi-level maze generation
License
MIT
Version
v0.1.0 - Initial release with core functionality
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mazewright-0.2.0.tar.gz
(15.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mazewright-0.2.0.tar.gz.
File metadata
- Download URL: mazewright-0.2.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83561e5c7c71c674420e606ae4eb5a737bfb4c1d0d52ddd407e60b6f99799cc2
|
|
| MD5 |
af4331d45d5c12823cb8ac27d73890df
|
|
| BLAKE2b-256 |
9554747156d7778aac25fe5339fdc513a76b3a2f4c2a37be556d19143fa78534
|
File details
Details for the file mazewright-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mazewright-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e49b9524ec689ecbeb6f3e070d246582b496a7d2363ce273a3848af4572e608d
|
|
| MD5 |
3b41a008af90d7ac915920318a2f499a
|
|
| BLAKE2b-256 |
afec402d4d51becd2b1af65784b71af04f3b9579230422d8a04bed2bf7f632a2
|