forked from AstronomicalClockTeam/AstroClock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstroProgram.py
More file actions
161 lines (125 loc) · 3.63 KB
/
AstroProgram.py
File metadata and controls
161 lines (125 loc) · 3.63 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python 3
# AstroClock
# Ethan Dall & Steven Thompson
# 3-21-18
import os
import pygame
import math
import time
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
# time
walk = 0
type_x = 0
type_y = 0
move_sec = 0
move_min = 0
move_hr = 0
HYP = 180
timeCount = 0
timeSec = 1000
timeMin = 6000
timeHr = 3600000
rotate = 360
offset = 15
tm_sec = 0
tm_min = 0
tm_hr = 0
# dictionary to hold numeral for printing
numeral_dict = {}
def setxAngleAttribute(x_angle):
x = (HYP * math.cos(math.radians(x_angle)))
return x
def setyAngleAttribute(y_angle):
y = (HYP * math.sin(math.radians(y_angle)))
return y
# Starts Pygame
pygame.init()
# Set the width and height of the screen [width, height]
size = (400, 400)
screen = pygame.display.set_mode(size)
# Fonts
name_font = pygame.font.SysFont('Times New Roman.ttf', 25)
pygame.display.set_caption("Astronomical Clock")
# Numbers to be drawn
for i in range(1, 25):
val = i
numeral = ''
numeral += 'X' * (i // 10)
if i % 10 == 9:
numeral += 'IX'
val -= 9
else:
cost = i % 10 // 5
numeral += 'V' * cost
val -= cost * 5
if val % 5 == 4 and val != 9:
numeral += 'IV'
else:
numeral += 'I' * (val % 5)
numeral_dict[str(i)] = name_font.render(numeral, 1, (0, 0, 0))
class Clock(object):
def __init__(self):
self.hour24_face()
self.hour_hands()
@staticmethod
def hour24_face():
# +200 because 200 is center and numbers to need to rotate around it
for i in range(1, 25):
coords = (270 + (offset * i)) % 360
screen.blit(numeral_dict[str(i)], (setxAngleAttribute(coords) + 190, setyAngleAttribute(coords) + 190))
@staticmethod
def hour_hands():
"""Runs and Draws the Seconds-Hand"""
secX = (HYP * math.cos(math.radians(move_sec))) + 200
secY = (HYP * math.sin(math.radians(move_sec))) + 200
pygame.draw.line(screen, RED, (200, 200), (secX, secY), 2)
"""Runs and Draws the Minutes-Hand"""
minX = (HYP * math.cos(math.radians(move_min))) + 200
minY = (HYP * math.sin(math.radians(move_min))) + 200
pygame.draw.line(screen, BLACK, (200, 200), (minX, minY), 3)
"""Runs and Draws the Hours-Hand"""
hrX = (HYP * math.cos(math.radians(move_hr))/1.5) + 200
hrY = (HYP * math.sin(math.radians(move_hr))/1.5) + 200
pygame.draw.line(screen, BLACK, (200, 200), (hrX, hrY), 3)
frame = Clock()
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# background image.
screen.fill(WHITE)
# --- Drawing code should go here
pygame.draw.circle(screen, BLACK, (200, 200), 200, 1)
frame.hour_hands()
frame.hour24_face()
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# Updates Seconds
tm_sec = time.localtime()[5]
move_sec = (tm_sec * 6 - 90) % 360
# Updates Minutes
tm_min = time.localtime()[4]
if (tm_hr % 2) != 0:
move_min = (tm_min * 3 + 90)
else:
move_min = (tm_min * 3 - 90) % 360
# Updates Hours
tm_hr = time.localtime()[3]
if tm_min < 180:
move_hr = (15 * tm_hr) - 90
elif tm_min >= 180:
move_hr = ((15 * tm_hr) - 90) * 2
# --- Limit to 60 frames per second
clock.tick(60)
# Close the window and quit.
pygame.quit()