commit 5df22bd0dea428ec77a61ba423a089d7ce13f885 Author: Klaas Börgmann Date: Wed May 22 12:20:38 2024 +0200 first commit diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/uhr.py b/uhr.py new file mode 100644 index 0000000..7fa9956 --- /dev/null +++ b/uhr.py @@ -0,0 +1,58 @@ +import pygame +import datetime +import math + +def draw_number_hand(screen, value, max_value, center, length, thickness, color, rep): + angle = value / max_value * 360 + angle_rad = math.radians(angle - 90) # Adjust by 90 degrees to align with clock + + # Draw the hand as repeated numbers + for i in range(1, rep): # number of repetitions + offset = length / rep * i + x = center[0] + offset * math.cos(angle_rad) + y = center[1] + offset * math.sin(angle_rad) + rendered_text = font.render(str(value), True, color) + text_rect = rendered_text.get_rect(center=(x, y)) + screen.blit(rendered_text, text_rect) + +# Definitions +size = 500 +center = (size/2, size/2) +hour_hand_length = 200 +minute_hand_length = 250 +second_hand_length = 270 +hand_thickness = 3 + +# Initialize Pygame and Window +pygame.init() +screen = pygame.display.set_mode([size, size]) +pygame.display.set_caption("Analog Clock") +font = pygame.font.Font(None, 36) + +# Run until the user asks to quit +running = True +while running: + # background + screen.fill((255, 255, 255)) + +# Get current time + now = datetime.datetime.now() + +# Draw the clock hands + draw_number_hand(screen, now.second, 60, center, second_hand_length, hand_thickness, (0, 0, 255),8) + draw_number_hand(screen, now.minute, 60, center, minute_hand_length, hand_thickness, (0, 255, 0),8) + draw_number_hand(screen, now.hour, 12, center, hour_hand_length, hand_thickness, (255, 0, 0), 6) + + # Update the display + pygame.display.flip() + + # Check for the quit event + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # 1 FPS + pygame.time.Clock().tick(60) + +# Quit +pygame.quit() \ No newline at end of file