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.

This commit is contained in:
dpanarello2
2025-10-05 18:10:00 -04:00
parent 797ac491a5
commit 3f5e231ac1

View File

@@ -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.write(str(h), align = "center", font = ("Arial", 50, "bold"))
t.backward(NUMBER_RADIUS)
draw_clock()
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()