-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorrery.py
executable file
·109 lines (94 loc) · 3.24 KB
/
orrery.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
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
#!/usr/bin/env python
# Python orrery
import pygame
import time, math
import orrp
RES = 150 # internal resolution
SRES = 600 # window size
ANIM_SPEED = 4 # animation speed factor
class Orr:
def __init__(s):
pygame.init()
s.res = SRES, SRES
s.screen = pygame.display.set_mode(s.res, pygame.RESIZABLE)
pygame.display.set_caption('Orrery')
s.clock = pygame.time.Clock()
s.dazz = pygame.Surface((RES, RES))
s.plusDays = 0
s.anim = False
s.anim_start = 0
s.old_offset = -1e6
def events(s):
for event in pygame.event.get():
if event.type == pygame.QUIT: s.running = False
if event.type == pygame.VIDEORESIZE:
s.res = event.w, event.h
s.screen = pygame.display.set_mode(s.res, pygame.RESIZABLE)
if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
s.plusDays += 1
if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
s.plusDays -= 1
if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
s.plusDays += 30
if event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
s.plusDays -= 30
if event.type == pygame.KEYDOWN and event.key == pygame.K_PAGEUP:
s.plusDays += 365
if event.type == pygame.KEYDOWN and event.key == pygame.K_PAGEDOWN:
s.plusDays -= 365
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
s.plusDays = 0
if event.type == pygame.KEYDOWN and event.key == pygame.K_a:
s.anim = not s.anim
if s.anim:
s.anim_start = time.time()
else:
s.plusDays += ANIM_SPEED * (time.time() - s.anim_start)
def run(s):
s.running = True
while s.running:
s.clock.tick(5)
s.events()
s.update()
pygame.quit()
def update(s):
s.dazz.fill((0, 0, 0))
WIDTH, HEIGHT = RES, RES
PL_CENTER = (int(WIDTH / 2), int(WIDTH / 2))
seconds_absolute = time.time()
plusDays = 0
if s.anim:
ani = ANIM_SPEED * (time.time() - s.anim_start)
else:
ani = 0
offset = s.plusDays + ani
ti = time.localtime(seconds_absolute + 86400 * offset)
if offset != s.old_offset:
s.old_offset = offset
o1 = "%04u-%02u-%02u" % (ti[0], ti[1], ti[2])
if round(offset) == 0: o2 = ""
else: o2 = "(%+i days)" % round(offset)
if s.anim: o3 = "(animation on)"
else: o3 = ""
pygame.display.set_caption("%s %s %s" % (o1, o2, o3))
planets_dict = orrp.coordinates(ti[0], ti[1], ti[2], ti[3], ti[4])
pygame.draw.circle(s.dazz, (255, 255, 0), (PL_CENTER[0], PL_CENTER[1]), 4)
for i, el in enumerate(planets_dict):
r = 8 * (i + 1) + 2
pygame.draw.circle(s.dazz, (80, 80, 80), (PL_CENTER[0], PL_CENTER[1]), r, width = 1)
feta = math.atan2(el[0], el[1])
coordinates = (r * math.sin(feta), r * math.cos(feta))
coordinates = (coordinates[0] + PL_CENTER[0], HEIGHT - (coordinates[1] + PL_CENTER[1]))
for ar in range(0, len(orrp.planets_a[i][0]), 5):
x = orrp.planets_a[i][0][ar] - 50 + coordinates[0]
y = orrp.planets_a[i][0][ar + 1] - 50 + coordinates[1]
if x >= 0 and y >= 0:
c = (orrp.planets_a[i][0][ar + 2], orrp.planets_a[i][0][ar + 3],
orrp.planets_a[i][0][ar + 4])
pygame.draw.line(s.dazz, c, (int(x), int(y)), (int(x), int(y)))
tres = s.res[0], s.res[1]
out = pygame.transform.scale(s.dazz, tres)
s.screen.blit(out, (0, 0))
pygame.display.flip()
c = Orr()
c.run()