-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_clock.py
56 lines (45 loc) · 1.49 KB
/
draw_clock.py
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
50
51
52
53
54
55
56
from dataclasses import dataclass
from turtle import RawTurtle
from typing import NamedTuple
class ClockHands:
@classmethod
def get_hour_hand(cls):
return cls("arrow", "blue", (1, 10))
@classmethod
def get_minute_hand(cls):
return cls("arrow", "red", (1, 15))
@classmethod
def get_second_hand(cls):
return cls("arrow", "gold", (1, 20))
def __init__(self, shape, color, size):
self.shape = shape
self.color = color
self.size = size
@dataclass
class ClockTime:
hours: int
minutes: int
seconds: int
@property
def hours_angle(self) -> float:
"""Calculate angle of the hours hand."""
return (self.hours % 12) * 360 / 12 + self.minutes * 360 / (12 * 60)
@property
def minutes_angle(self) -> float:
"""Calculate angle of the minutes hand."""
return self.minutes * 360 / 60
@property
def seconds_angle(self) -> float:
"""Calculate angle of the seconds hand."""
return self.seconds * 360 / 60
@classmethod
def calculate_angles(cls, random_clock_values: "ClockTime") -> NamedTuple:
"""Calculates hands angles and returns a named tuple."""
Angles = NamedTuple(
"Angles", [("hours", float), ("minutes", float), ("seconds", float)]
)
return Angles(
hours=random_clock_values.hours_angle,
minutes=random_clock_values.minutes_angle,
seconds=random_clock_values.seconds_angle,
)