使用 Python 生成迷宫

源代码在这里

python-maze

Generate a maze using Python

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)

使用 Python 生成迷宫_第1张图片

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)

使用 Python 生成迷宫_第2张图片
If you want to know why it works, see here

试试其它图
使用 Python 生成迷宫_第3张图片

你可能感兴趣的:(数学,算法,迷宫,前端,深度优先搜索)