finish the animation generator maze

This commit is contained in:
Maoake Teriierooiterai
2026-03-27 16:49:13 +01:00
parent a3bbce861d
commit 3c072de0f4
5 changed files with 41 additions and 33 deletions
+2
View File
@@ -32,3 +32,5 @@ run_test_maze_gen:
PYTHONPATH=src uv run pytest tests/test_MazeGenerator.py PYTHONPATH=src uv run pytest tests/test_MazeGenerator.py
run_test: run_test:
uv run pytest uv run pytest
mlx:
uv run python3 test.py
+15 -12
View File
@@ -1,12 +1,9 @@
import os from typing import Any
from typing import Any, Callable, Generator
from src.AMazeIng import AMazeIng from src.AMazeIng import AMazeIng
from src.parsing import Parsing from src.parsing import Parsing
from mlx.mlx import Mlx from mlx.mlx import Mlx
import numpy as np import numpy as np
import math import math
from src.amaz_lib import Maze
import time
class MazeMLX: class MazeMLX:
@@ -15,6 +12,7 @@ class MazeMLX:
self.height = height self.height = height
self.width = width self.width = width
self.mlx_ptr = self.mlx.mlx_init() self.mlx_ptr = self.mlx.mlx_init()
self.generator = None
self.win_ptr = self.mlx.mlx_new_window( self.win_ptr = self.mlx.mlx_new_window(
self.mlx_ptr, width, height, "amazing" self.mlx_ptr, width, height, "amazing"
) )
@@ -37,6 +35,7 @@ class MazeMLX:
def clear_image(self) -> None: def clear_image(self) -> None:
self.buf[:] = b"\x00" * len(self.buf) self.buf[:] = b"\x00" * len(self.buf)
self.mlx.mlx_clear_window(self.mlx_ptr, self.win_ptr)
def put_line(self, start: tuple[int, int], end: tuple[int, int]) -> None: def put_line(self, start: tuple[int, int], end: tuple[int, int]) -> None:
sx, sy = start sx, sy = start
@@ -77,24 +76,28 @@ class MazeMLX:
if maze[y][x].get_west(): if maze[y][x].get_west():
self.put_line((x0, y0), (x0, y1)) self.put_line((x0, y0), (x0, y1))
self.mlx.mlx_put_image_to_window( self.mlx.mlx_put_image_to_window(
self.mlx_ptr, self.win_ptr, self.img_ptr, 0, 0) self.mlx_ptr, self.win_ptr, self.img_ptr, 0, 0)
def close_loop(self, _: Any): def close_loop(self, _: Any):
self.mlx.mlx_loop_exit(self.mlx_ptr) self.mlx.mlx_loop_exit(self.mlx_ptr)
def gen_maze(self, amazing: AMazeIng) -> None: def gen_maze(self, amazing: AMazeIng) -> None:
for output in amazing.generate(): self.generator = amazing.generate()
maze = output
maze.ascii_print()
self.clear_image()
self.update_maze(amazing.maze.get_maze())
def start(self, amazing: AMazeIng) -> None: def start(self, amazing: AMazeIng) -> None:
test = self.gen_maze(amazing) self.gen_maze(amazing)
# self.mlx.mlx_loop_hook(self.mlx_ptr, test, amazing) self.mlx.mlx_loop_hook(self.mlx_ptr, self.render, amazing)
self.mlx.mlx_hook(self.win_ptr, 33, 0, self.close_loop, None) self.mlx.mlx_hook(self.win_ptr, 33, 0, self.close_loop, None)
self.mlx.mlx_loop(self.mlx_ptr) self.mlx.mlx_loop(self.mlx_ptr)
def render(self, amazing: AMazeIng):
try:
next(self.generator)
self.update_maze(amazing.maze.get_maze())
# time.sleep(0.01)
except StopIteration:
pass
def main() -> None: def main() -> None:
mlx = None mlx = None
+3 -3
View File
@@ -1,8 +1,8 @@
WIDTH=15 WIDTH=20
HEIGHT=15 HEIGHT=20
ENTRY=1,1 ENTRY=1,1
EXIT=2,2 EXIT=2,2
OUTPUT_FILE=maze.txt OUTPUT_FILE=maze.txt
PERFECT=True PERFECT=False
GENERATOR=DFS GENERATOR=DFS
SOLVER=AStar SOLVER=AStar
-2
View File
@@ -1,8 +1,6 @@
from dataclasses import dataclass from dataclasses import dataclass
import numpy import numpy
from .Cell import Cell
from .MazeGenerator import MazeGenerator
@dataclass @dataclass
+21 -16
View File
@@ -1,19 +1,24 @@
D39393951579553 B9153957955513953953
BAAC6AE96956952 AEA96A9569792C6BAAD6
AAA97C383C396D2 C5443AA9169281102C53
86AC156E83AC53E 95556A82816C2AC2A952
A943C553EC453C3 A93916A86A956C3A86D6
AE96FB96FFFBC3A AEC6C542944513806953
C56BFC4157FA96A C395553AC393C2AC787A
9516FFFAFFF86BA BC69512C7AAC56855692
C3C513FAFD52D2A A952BAAF96AFFFAD53AE
94796AFAFFFA92A A810686FC5057FC516C3
A93C3ABC3D546EA AAC4543FFFAFFFB96952
AAA96C2BC555552 AC5553817FAFD52ABC3A
EA8693C43B91796 815552843FEFFF80296A
96E96A93C6AC3AB AC553A85413D55406C12
C5547C6C5547C46 C53BAAC392C3953C13AA
9386AC386A9683C56AAA
846903AE96C568517C2A
AD3A82C385397C3C5546
C12AA87AA94293AD5513
D46C6C5446D46C45556E
1,1 1,1
2,2 2,2
ES SSEEENENWWWS