generated from mwc/project_drawing
59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
# drawing.py
|
|
# ----------
|
|
# By Diana Panarello
|
|
#
|
|
# This program will be a clock that moves.
|
|
|
|
import turtle
|
|
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(-10)
|
|
t.pensize(14)
|
|
t.color("black")
|
|
t.goto(0, -200)
|
|
t.pendown()
|
|
RADIUS = 200
|
|
t.circle(RADIUS)
|
|
NUMBER_RADIUS = RADIUS - 30
|
|
t = turtle.Turtle()
|
|
t.penup()
|
|
t.goto(5, -30)
|
|
t.pensize(20)
|
|
t.color("black")
|
|
for h in range(1, 13):
|
|
angle = 30 * (3 - h)
|
|
t.speed(-5)
|
|
t.setheading(angle)
|
|
t.forward(NUMBER_RADIUS)
|
|
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()
|