Clock Face¶
By the end of this lab you'll be able to:
- Draw a clock face with tick marks and hour numbers
- Convert hours, minutes, and seconds into angles for clock hands
- Use
setheading()to point each hand at the correct angle
A complete analog clock face — outer ring with 60 tick marks, 12 numbered hours, and three hands (hour, minute, second) drawn at computed angles.
Welcome to the Clock Face!
An analog clock is a math problem: convert time into angles!
The minute hand moves 6° per minute, the hour hand moves 0.5° per minute.
Let's compute it and draw it!
How It Works¶
Angles for hands: second_angle = 90 - seconds * 6, minute_angle = 90 - minutes * 6 - seconds * 0.1, hour_angle = 90 - hours * 30 - minutes * 0.5. A draw_hand(angle, length, width) function draws a hand at the given angle.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
What Do You Think Will Happen?
The code sets hours=10, minutes=10, seconds=30.
Before running, look at an analog clock and imagine where the hands should point.
Make your prediction — then click Run!
Try It Now¶
A clock showing 10:10:30 — the hour hand between 10 and 11 (already past the 10), minute hand at 2 (10 minutes), second hand at 3 (30 seconds). Were you right?
How It Works¶
Clock angles: - Each second = 6° clockwise = −6° in turtle angle - Each minute = 6° clockwise; the second also moves the minute hand slightly (0.1° per second) - Each hour = 30° clockwise; the minute also moves the hour hand (0.5° per minute)
Explanation Table¶
| Line | What it does |
|---|---|
sec_angle = 90 - seconds * 6 |
0s = 12 o'clock = 90°, each second = −6° |
min_angle = 90 - minutes*6 - seconds*0.1 |
Minute hand moves smoothly |
hr_angle = 90 - hours*30 - minutes*0.5 |
Hour hand moves between hours |
i % 5 == 0 |
Every 5th tick is a long hour tick |
Learning Check¶
Your Turn — Change the Time
Change to hours=3, minutes=45, seconds=0.
Before running, visualize where each hand will point. Then run to verify!
3:45:00 — the minute hand at 9, the hour hand 3/4 of the way between 3 and 4 (because 45 minutes = 3/4 of the way to the next hour).
Experiments¶
-
Display your current time. Use Python's
datetimemodule:import datetime; now = datetime.datetime.now()thenhours = now.hour % 12; minutes = now.minute; seconds = now.second. You'll know it worked when the clock shows the actual current time. -
Add a colored clock face. Draw a filled circle in a light color behind the tick marks. You'll know it worked when the clock has a colored background.
-
Make the hands colored. Use different colors for hour, minute, and second hands. You'll know it worked when each hand is visually distinct.
-
Add Roman numerals. Replace the number labels with Roman numerals. You'll know it worked when
I,II,III... appear around the clock.
Tick Tock!
You built a working analog clock face from scratch using angle math!
The same angle = 90 - n * step formula works for any clock-like display.
Up next: Spirograph Drawer — interactive spirograph with changing parameters.