Added working indication to maze visualizer

This commit is contained in:
Kyler Olsen 2025-01-31 12:12:52 -07:00
parent f704fb0343
commit 15c10dac2e
1 changed files with 12 additions and 10 deletions

View File

@ -8,10 +8,11 @@ pygame.init()
# Constants
# CELL_SIZE = 10
# CLOCK_TICK = 20
HIGHLIGHT_COLOR = (0, 255, 255) # Cyan for highlighted cells
SECONDARY_COLOR = (0, 0, 255) # Blue for secondary highlighted cells
WALL_COLOR = (0, 0, 0) # Black for walls
PATH_COLOR = (255, 255, 255) # White for paths
HIGHLIGHT_COLOR = (0, 255, 255) # Cyan for highlighted cells
SECONDARY_COLOR = (0, 0, 255) # Blue for secondary highlighted cells
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
class MazeVisualizer:
@ -21,6 +22,7 @@ class MazeVisualizer:
self.screen_height = maze.height * CELL_SIZE
self.screen = pygame.display.set_mode(
(self.screen_width, self.screen_height))
self.working = False
pygame.display.set_caption("Maze Generator Visualization")
def draw_maze(self):
@ -30,7 +32,7 @@ class MazeVisualizer:
if self.maze[x, y]:
pygame.draw.rect(
self.screen,
WALL_COLOR,
WALL_COLOR if self.working else WORKING_WALL_COLOR,
pygame.Rect(
x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE)
)
@ -58,7 +60,7 @@ class MazeVisualizer:
def run(self):
clock = pygame.time.Clock()
running = True
generation_complete = True
self.working = True
while running:
for event in pygame.event.get():
@ -66,13 +68,13 @@ class MazeVisualizer:
running = False
if event.type == pygame.KEYUP:
if event.key == pygame.K_SPACE:
generation_complete = not generation_complete
self.working = not self.working
if event.key == pygame.K_o:
if isinstance(self.maze, maze.VectorWrapper):
self.maze = maze.VectorWrapper(
maze.OriginShift.clone(self.maze.maze))
if event.key == pygame.K_s:
if generation_complete: self.maze.step()
if self.working: self.maze.step()
if event.key == pygame.K_h:
for _ in range(100):
if not self.maze.step(): break
@ -86,8 +88,8 @@ class MazeVisualizer:
self.maze = maze.VectorWrapper.convert(self.maze)
# Only step through the algorithm if it's not finished
if not generation_complete:
generation_complete = not self.maze.step()
if not self.working:
self.working = not self.maze.step()
# Draw the maze regardless of generation state
self.draw_maze()