feat(visualizer): add status print to terminal

This commit is contained in:
2025-04-13 12:35:09 +02:00
parent d3fcba9ebc
commit ac709f9925
2 changed files with 27 additions and 2 deletions

View File

@@ -1,2 +1,3 @@
pygame==2.6.1
pygcode==0.2.1
pygcode==0.2.1
colorama==0.4.6

View File

@@ -1,4 +1,6 @@
import pygame
import sys
from colorama import Fore, Style
class Visualizer:
def __init__(self, positions : list[tuple[float, float, float]], screen_dimensions : tuple[int, int], gcode_size : tuple[float, float]):
@@ -30,6 +32,26 @@ class Visualizer:
self.screen = pygame.display.set_mode(self.screen_dimensions)
self.clock = pygame.time.Clock()
def _print_status(self) -> None:
normalized_x = self.prev_x / self.screen.get_width()
normalized_y = self.prev_y / self.screen.get_height()
pen_active = self.prev_z < 0
# Clear the terminal with ANSI code
print("\033c", end="")
# X-axis bar
x_bar = f"{Fore.GREEN}{'#'*int(normalized_x*100)}{Style.RESET_ALL}{' '*int((1.0-normalized_x)*100)}"
print(f"X: |{x_bar}| {(normalized_x*100):.2f}%")
# Y-axis bar
y_bar = f"{Fore.BLUE}{'#'*int(normalized_y*100)}{Style.RESET_ALL}{' '*int((1.0-normalized_y)*100)}"
print(f"Y: |{y_bar}| {(normalized_y*100):.2f}%")
# Pen status
pen_status = f"{Fore.GREEN}Active{Style.RESET_ALL}" if pen_active else f"{Fore.RED}Inactive{Style.RESET_ALL}"
print(f"Pen: {pen_status}")
def visualize(self) -> None:
running = True
while running:
@@ -61,5 +83,7 @@ class Visualizer:
x1, y1, x2, y2 = drawn_line
pygame.draw.line(self.screen, (255, 255, 255), (int(x1), int(y1)), (int(x2), int(y2)), 2)
self._print_status()
pygame.display.flip()
self.clock.tick(60)
self.clock.tick(10)