guofei9987 / python-maze

Generate a maze using Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python-maze

Generate a maze using Python

Download this repository, then use maze.py as below:

import matplotlib.pyplot as plt
import numpy as np


from maze import Maze
maze=np.zeros(shape=(100,100))
start_point=np.array([0,0])
maze_generator=Maze(maze, start_point)
plt.imshow(maze_generator.maze)

maze

Generate a maze with a picture using Python

import cv2
pic = cv2.imread('duck.jfif')
pic = cv2.cvtColor(pic, cv2.COLOR_BGR2GRAY)
pic = cv2.resize(pic, (100, 100))
pic = (pic > pic.mean()) * (-1)

from maze import Maze

start_point=np.array([50,50])
maze_generator=Maze(pic, start_point)
plt.imshow(maze_generator.maze)

duck_maze

If you want to know why it works, see here

Go and try other pictures heart_maze

About

Generate a maze using Python

License:MIT License


Languages

Language:Python 100.0%