From 3f5e231ac130d6ece06770dcca710aace933ab03 Mon Sep 17 00:00:00 2001 From: dpanarello2 Date: Sun, 5 Oct 2025 18:10:00 -0400 Subject: [PATCH] For my final submission, I decided to make a code that has the coder input a time and when you run it, the clock displays that time. For a future project, I want to try and make a clock with hands that move. --- drawing.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drawing.py b/drawing.py index ee3be64..a269463 100644 --- a/drawing.py +++ b/drawing.py @@ -1,17 +1,26 @@ # drawing.py # ---------- -# By ____(you)___________ +# By Diana Panarello # -# (Briefly describe what this program does.) +# This program will be a clock that moves. import turtle -def draw_clock(): +RADIUS = 200 +def draw_hand(t, length, heading, color, width): + t.penup() + t.goto(0, 0) + t.color(color) + t.pensize(width) + t.setheading(heading) + t.pendown() + t.forward(length) +def draw_clock(hour, minutes): screen = turtle.Screen() screen.setup(width=600, height=600) screen.bgcolor("lightgray") t = turtle.Turtle() t.penup() - t.speed(0) + t.speed(-10) t.pensize(14) t.color("black") t.goto(0, -200) @@ -24,11 +33,26 @@ def draw_clock(): t.goto(5, -30) t.pensize(20) t.color("black") - for hour in range(1, 13): - angle = 30 * (3 - hour) + for h in range(1, 13): + angle = 30 * (3 - h) + t.speed(-5) t.setheading(angle) t.forward(NUMBER_RADIUS) - t.write(str(hour), align = "center", font = ("Arial", 50, "bold")) - t.backward(NUMBER_RADIUS) -draw_clock() + t.write(str(h), align = "center", font = ("Arial", 50, "bold")) + t.backward(NUMBER_RADIUS) + t_hand = turtle.Turtle() + t_hand.speed(-5) + t_hand.hideturtle() + minute_angle_clockwise = minutes * 6 + minute_heading = 90 - minute_angle_clockwise + hour_angle_clockwise = (hour % 12 + minutes / 60) * 30 + hour_heading = 90 - hour_angle_clockwise + HOUR_LENGTH = RADIUS * 0.5 + draw_hand(t_hand, HOUR_LENGTH, hour_heading, "black", 8) + MINUTE_LENGTH = RADIUS * 0.75 + draw_hand(t_hand, MINUTE_LENGTH, minute_heading, "black", 8) + + +draw_clock(3, 00) + turtle.done()