-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (52 loc) · 1.79 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
import math
import pygame as pg
def init():
"""Initialization calls"""
pg.init()
screen = pg.display.set_mode((800, 600), flags=pg.RESIZABLE)
return screen, pg.time.Clock()
def coords(x, y):
"""Used to translate the coordinates origin"""
return 300 + x, 300 + y
def mainloop(screen: pg.Surface, main_clock: pg.time.Clock):
background_color = "black"
run = True
time = 0 # angle for polar-to-cartesian conversion
r = 100
wave = []
circles = 3
circle_color = (100, 100, 100)
while run:
for event in pg.event.get():
if event.type == pg.QUIT:
run = False
elif event.type == pg.KEYDOWN:
if event.key == pg.K_UP:
circles += 1
elif event.key == pg.K_DOWN:
circles -= 1
screen.fill(background_color)
x, y = 0, 0
for i in range(0, circles):
previous_x = x
previous_y = y
n = i * 2 + 1
radius = r * (4.0 / (n * math.pi))
x += radius * math.cos(n * time)
y += radius * math.sin(n * time)
pg.draw.line(screen, "white", coords(previous_x, previous_y), coords(x, y))
pg.draw.circle(screen, circle_color,
coords(previous_x, previous_y), radius=radius, width=1)
wave.insert(0, y)
if len(wave) > 2:
pg.draw.aalines(screen, pg.Color("white"), False,
[coords(200 + i, wave[i]) for i in range(len(wave))], 1 )
pg.draw.line(screen, pg.Color("white"), coords(x, y), coords(200, wave[0]), 1)
time -= 0.02
pg.display.flip()
main_clock.tick(60)
def main():
mainloop(*init())
pg.quit()
if __name__ == "__main__":
main()