Added working indication to maze visualizer
This commit is contained in:
parent
f704fb0343
commit
15c10dac2e
14
visualize.py
14
visualize.py
|
@ -11,6 +11,7 @@ pygame.init()
|
||||||
HIGHLIGHT_COLOR = (0, 255, 255) # Cyan for highlighted cells
|
HIGHLIGHT_COLOR = (0, 255, 255) # Cyan for highlighted cells
|
||||||
SECONDARY_COLOR = (0, 0, 255) # Blue for secondary highlighted cells
|
SECONDARY_COLOR = (0, 0, 255) # Blue for secondary highlighted cells
|
||||||
WALL_COLOR = (0, 0, 0) # Black for walls
|
WALL_COLOR = (0, 0, 0) # Black for walls
|
||||||
|
WORKING_WALL_COLOR = (32, 32, 32) # Grey for walls while working
|
||||||
PATH_COLOR = (255, 255, 255) # White for paths
|
PATH_COLOR = (255, 255, 255) # White for paths
|
||||||
|
|
||||||
class MazeVisualizer:
|
class MazeVisualizer:
|
||||||
|
@ -21,6 +22,7 @@ class MazeVisualizer:
|
||||||
self.screen_height = maze.height * CELL_SIZE
|
self.screen_height = maze.height * CELL_SIZE
|
||||||
self.screen = pygame.display.set_mode(
|
self.screen = pygame.display.set_mode(
|
||||||
(self.screen_width, self.screen_height))
|
(self.screen_width, self.screen_height))
|
||||||
|
self.working = False
|
||||||
pygame.display.set_caption("Maze Generator Visualization")
|
pygame.display.set_caption("Maze Generator Visualization")
|
||||||
|
|
||||||
def draw_maze(self):
|
def draw_maze(self):
|
||||||
|
@ -30,7 +32,7 @@ class MazeVisualizer:
|
||||||
if self.maze[x, y]:
|
if self.maze[x, y]:
|
||||||
pygame.draw.rect(
|
pygame.draw.rect(
|
||||||
self.screen,
|
self.screen,
|
||||||
WALL_COLOR,
|
WALL_COLOR if self.working else WORKING_WALL_COLOR,
|
||||||
pygame.Rect(
|
pygame.Rect(
|
||||||
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
|
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
|
||||||
)
|
)
|
||||||
|
@ -58,7 +60,7 @@ class MazeVisualizer:
|
||||||
def run(self):
|
def run(self):
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
running = True
|
running = True
|
||||||
generation_complete = True
|
self.working = True
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
@ -66,13 +68,13 @@ class MazeVisualizer:
|
||||||
running = False
|
running = False
|
||||||
if event.type == pygame.KEYUP:
|
if event.type == pygame.KEYUP:
|
||||||
if event.key == pygame.K_SPACE:
|
if event.key == pygame.K_SPACE:
|
||||||
generation_complete = not generation_complete
|
self.working = not self.working
|
||||||
if event.key == pygame.K_o:
|
if event.key == pygame.K_o:
|
||||||
if isinstance(self.maze, maze.VectorWrapper):
|
if isinstance(self.maze, maze.VectorWrapper):
|
||||||
self.maze = maze.VectorWrapper(
|
self.maze = maze.VectorWrapper(
|
||||||
maze.OriginShift.clone(self.maze.maze))
|
maze.OriginShift.clone(self.maze.maze))
|
||||||
if event.key == pygame.K_s:
|
if event.key == pygame.K_s:
|
||||||
if generation_complete: self.maze.step()
|
if self.working: self.maze.step()
|
||||||
if event.key == pygame.K_h:
|
if event.key == pygame.K_h:
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
if not self.maze.step(): break
|
if not self.maze.step(): break
|
||||||
|
@ -86,8 +88,8 @@ class MazeVisualizer:
|
||||||
self.maze = maze.VectorWrapper.convert(self.maze)
|
self.maze = maze.VectorWrapper.convert(self.maze)
|
||||||
|
|
||||||
# Only step through the algorithm if it's not finished
|
# Only step through the algorithm if it's not finished
|
||||||
if not generation_complete:
|
if not self.working:
|
||||||
generation_complete = not self.maze.step()
|
self.working = not self.maze.step()
|
||||||
|
|
||||||
# Draw the maze regardless of generation state
|
# Draw the maze regardless of generation state
|
||||||
self.draw_maze()
|
self.draw_maze()
|
||||||
|
|
Loading…
Reference in New Issue