A Python library for generating and visualizing mazes with custom properties.
Project description
Maze Generator
Maze Generator is a Python library for generating, visualizing, and saving maze structures. It allows you to create random mazes, visualize them using matplotlib, and save/load them in various formats including CSV and text files. This library is ideal for educational purposes, game development, or just for fun!
Features
- Maze Generation: Generate mazes of any size with random paths using the iterative backtracking algorithm.
- Visualization: Visualize mazes using
matplotlibwith start and end points highlighted. - File Handling: Save and load mazes in CSV or text formats.
Installation
You can install the library via pip:
pip install pip install maze-generator-jotbleach==1.1.0
Usage
1. Creating and Generating a Maze
from maze_generator_jotbleach import MazeGenerator
# Create a MazeGenerator object with specified dimensions
maze = MazeGenerator(width=21, height=21, seed=42)
# Generate the maze
maze.generate_maze()
# Retrieve the maze as a grid (2D list)
maze_grid = maze.get_maze()
2. Visualizing the Maze
# Visualize the generated maze
maze.visualize_maze()
# Save the visualization as an image
maze.visualize_maze(save_path='maze.png')
3. Saving and Loading the Maze
Save as CSV
# Save the maze grid to a CSV file
maze.save_maze_as_csv('maze.csv')
Load from CSV
# Load a maze grid from a CSV file
maze.load_maze_from_csv('maze.csv')
4. Customizing the Maze
You can also manually set a maze using a 2D list and visualize it.
custom_maze = [
[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 1, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]
]
maze.set_maze(custom_maze)
maze.visualize_maze()
API Reference
class MazeGenerator(width=None, height=None, seed=None)
Parameters:
width(int, optional): The width of the maze (must be an odd number).height(int, optional): The height of the maze (must be an odd number).seed(int, optional): Seed value for the random number generator to ensure reproducibility.
Methods:
generate_maze(): Generates a new maze.set_maze(maze_array): Sets the maze grid from a given 2D list.get_start_end_positions(): Returns the start and end positions of the maze.visualize_maze(save_path=None): Visualizes the maze usingmatplotlib.save_maze_as_csv(file_path): Saves the maze grid to a CSV file.load_maze_from_csv(file_path): Loads the maze grid from a CSV file.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
- Matplotlib for visualization.
- NumPy for efficient array handling.
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
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 maze_generator_jotbleach-1.1.0.tar.gz.
File metadata
- Download URL: maze_generator_jotbleach-1.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
520b533ac7f95982586eb2b9fa4a41e20f170bdf02831074378f94419d05d4a1
|
|
| MD5 |
a245bce0b2f5d1c83d98e34d04e85ec5
|
|
| BLAKE2b-256 |
e7636b689987fa5a8f69fd6715f2a7e921e7129792f2b729fe0c6dbff8c0aea4
|
File details
Details for the file maze_generator_jotbleach-1.1.0-py3-none-any.whl.
File metadata
- Download URL: maze_generator_jotbleach-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf9441d2375a0c8b85908ef4e7afc72e07a7520be5b2087d931ca57035cae66c
|
|
| MD5 |
293553bd2efa91d1f03c8cdfe1ae0efa
|
|
| BLAKE2b-256 |
c52bfed49ec05ef540b980baa086543636a2b83b7a53398143d6af072c5932d2
|