Rotating lines like in the classic NES Super Mario brothers.
import kandinsky as kd import math import time def draw_line(x0, y0, length, angle_deg, color=(0, 0, 0)): angle_rad = math.radians(angle_deg) x1 = int(x0 + length * math.cos(angle_rad)) y1 = int(y0 - length * math.sin(angle_rad)) steps = max(abs(x1 - x0), abs(y1 - y0)) for i in range(steps + 1): x = int(x0 + (x1 - x0) * i / steps) y = int(y0 + (y1 - y0) * i / steps) kd.set_pixel(x, y, color) def rotate_line(x0, y0, length, color=(0, 0, 0)): angle = 0 while True: kd.fill_rect(0, 0, 320, 240, (255, 255, 255)) # Clear screen (white background) draw_line(x0, y0, length, angle, color) # Draw the line at the current angle angle += 5 # Increment the angle for the next frame if angle >= 360: angle = 0 # Reset angle after a full circle time.sleep(0.05) # Delay for animation effect rotate_line(160, 120, 50, (255, 0, 0)) # Rotate a red line