Update 3 files

- /images/solved/Maze_1.png
- /images/Maze_1.png
- /generator.py
This commit is contained in:
Jan BELLON 2024-03-03 00:25:16 +00:00
parent 7e7ab04f59
commit 8a0fad9a61
3 changed files with 13 additions and 14 deletions

View File

@ -10,7 +10,8 @@ os.system('cls' if os.name == 'nt' else 'clear')
folder = os.getcwd() folder = os.getcwd()
map_size = input("Maze size : ") maze_size = input("Maze size : ")
maze_name = input("Maze ID : ")
wall_thickness = 3 # in pixels wall_thickness = 3 # in pixels
@ -19,8 +20,8 @@ image_size = (1920, 1080)
wall_list = [[],[]] wall_list = [[],[]]
for i in wall_list: for i in wall_list:
for x in range(1, round(map_size) + 1): for x in range(1, round(maze_size) + 1):
for y in range(1, round(map_size) + 1): for y in range(1, round(maze_size) + 1):
i.append((x, y)) i.append((x, y))
image = Image.new( image = Image.new(
@ -29,11 +30,11 @@ image = Image.new(
color = (255,255,255) color = (255,255,255)
) )
padding = 2 * image_size[1] / map_size padding = 2 * image_size[1] / maze_size
pixel_size = round((image_size[1] - padding * 2) / map_size) pixel_size = round((image_size[1] - padding * 2) / maze_size)
maze_pict = map_size * pixel_size maze_pict = maze_size * pixel_size
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
@ -48,17 +49,15 @@ closed_list = []
path = {} path = {}
print(f"Map size : {map_size} x {map_size}") print(f"maze size : {maze_size} x {maze_size}")
map_Name = input("Map Number : ")
time.sleep(2) time.sleep(2)
def build_grid(x, y): def build_grid(x, y):
for n in range(map_size): for n in range(maze_size):
x = 1 x = 1
y += 1 y += 1
for m in range(map_size): for m in range(maze_size):
grid.append((x, y)) grid.append((x, y))
x += 1 x += 1
@ -177,7 +176,7 @@ draw.rectangle(
) )
print("Maze successfully generated") print("Maze successfully generated")
image.save(f"{folder}/images/Maze_{map_Name}.png") image.save(f"{folder}/images/Maze_{maze_name}.png")
def Path_tracker(x, y): def Path_tracker(x, y):
position_x = x * pixel_size + decalage + 1 position_x = x * pixel_size + decalage + 1
@ -196,6 +195,6 @@ def path_tracer(x, y):
x, y = path[x, y] x, y = path[x, y]
Path_tracker(x,y) Path_tracker(x,y)
path_tracer(map_size, map_size) path_tracer(maze_size, maze_size)
image.save(f"{folder}/images/solved/Maze_{map_Name}.png") image.save(f"{folder}/images/solved/Maze_{maze_name}.png")

BIN
images/Maze_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
images/solved/Maze_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB