diff --git a/visualizer.py b/visualizer.py index dcb6a7c..d4ace48 100644 --- a/visualizer.py +++ b/visualizer.py @@ -39,27 +39,27 @@ class Visualizer: self.screen.fill((0, 0, 0)) - pos = self.positions[self.idx] - x, y, z = self._transform_coordinates(pos) - if self.prev_z < 0 and z < 0: - self.drawn_lines.append((self.prev_x, self.prev_y, x, y)) - elif z > 0: - self.travel_moves.append((self.prev_x, self.prev_y, x, y)) + if self.idx < len(self.positions): + pos = self.positions[self.idx] + x, y, z = self._transform_coordinates(pos) + if self.prev_z < 0 and z < 0: + self.drawn_lines.append((self.prev_x, self.prev_y, x, y)) + elif z > 0: + self.travel_moves.append((self.prev_x, self.prev_y, x, y)) + self.prev_x, self.prev_y, self.prev_z = x, y, z + # Draw the current position + pygame.draw.circle(self.screen, (255, 0, 0), (int(x), int(y)), 5) + self.idx += 1 + # Draw travel moves for travel_move in self.travel_moves: x1, y1, x2, y2 = travel_move - # Draw a line from the previous position to the current position pygame.draw.line(self.screen, (0, 0, 255), (int(x1), int(y1)), (int(x2), int(y2)), 2) + + # Draw drawn lines for drawn_line in self.drawn_lines: x1, y1, x2, y2 = drawn_line - # Draw a line from the previous position to the current position pygame.draw.line(self.screen, (255, 255, 255), (int(x1), int(y1)), (int(x2), int(y2)), 2) - self.prev_x, self.prev_y, self.prev_z = x, y, z - # Draw the current position - pygame.draw.circle(self.screen, (255, 0, 0), (int(x), int(y)), 5) - self.idx += 1 - if self.idx >= len(self.positions): - running = False pygame.display.flip() - self.clock.tick(10) \ No newline at end of file + self.clock.tick(60) \ No newline at end of file