-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·131 lines (110 loc) · 3.45 KB
/
main.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
import sys, pygame, random, math
from pprint import pprint
from galaxy import Spiral
from coordinate import Cartesian
pygame.init()
clock = pygame.time.Clock()
#random.seed(8314569173651)
size = width, height = 1000, 1000
center = center_x, center_y = width / 2, height / 2
speed = -0.0001
#angle = 0
#background = 51
#star_count = 450
star_count = 4000
black = 0, 0, 0
background = 51, 51, 51
white = 255, 255, 255
def create_fonts(font_sizes_list):
"Creates different fonts with one list"
fonts = []
for size in font_sizes_list:
fonts.append(
pygame.font.SysFont("Arial", size))
return fonts
fonts = create_fonts([32, 16, 14, 8])
class PolarCoordinate(object):
def __init__(self, x: int, y: int, angle: int, distance: float):
self.x = x
self.y = y
self.angle = angle
self.distance = distance
def cartesian_x(self):
return math.cos(self.angle) * self.distance
def cartesian_y(self):
return math.sin(self.angle) * self.distance
def cartesian_coordinate(self):
return (
self.cartesian_x(),
self.cartesian_y()
)
class Star(object):
def __init__(self, coordinate: PolarCoordinate):
self.coordinate = coordinate
def get_x(self):
return self.coordinate.cartesian_x()
def get_y(self):
return self.coordinate.cartesian_y()
def get_cartesian(self):
return self.coordinate.cartesian_coordinate()
def relative_cartesian(self): # need a name nerd!
return (
center_x + self.get_x(),
center_y + self.get_y()
)
def getGalaxy(star_count, radius):
stars = []
for star in range(star_count):
distance = random.random() * radius
angle = random.random() * 2 * math.pi
coordinate = PolarCoordinate(
0,
0,
angle,
distance
)
stars.append(Star(coordinate))
return stars
def rotate_around(coordinate, center, angleInDegrees):
angleInRadians = angleInDegrees * (math.pi / 180)
cosTheta = math.cos(angleInRadians)
sinTheta = math.sin(angleInRadians)
return (
(cosTheta * (coordinate[0] - center[0]) -
sinTheta * (coordinate[1] - center[1]) + center[0]),
(sinTheta * (coordinate[0] - center[0]) +
cosTheta * (coordinate[1] - center[1]) + center[1])
)
def main():
rand = random.Random()
rand.seed(8314569173651)
#galaxy = getGalaxy(star_count, 300)
galaxy = Spiral(star_count, 20, 5, 0.01, rand).stars
#for star in galaxy:
# print(star.coordinate.angle)
screen = pygame.display.set_mode(size)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
screen.fill(background)
txt = fonts[1].render(str(int(clock.get_fps())), 0, pygame.Color(white))
screen.blit(txt, (0, 0))
dist = 0.0
for star in galaxy:
# location = rotate_around(
# star.relative_cartesian(),
# center,
# 0.2
# )
star.coordinate.angle += speed
pygame.draw.circle(
screen,
white,
star.coordinate.get_relative_cartesian(Cartesian(size[0]/2, size[1]/2)),
1.0
)
clock.tick(60)
pygame.display.flip()
if __name__ == "__main__":
main()