-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanar.py
57 lines (41 loc) · 1.37 KB
/
planar.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
import pmma
import math
import random
pmma.init()
display = pmma.Display()
display.create(1920, 1080, fullscreen=True)
events = pmma.Events(display)
advmath = pmma.Math()
draw = pmma.Draw(display)
def degrees_to_radians(degrees):
return ((360/N_POINTS) * degrees) * (math.pi / 180)
N_POINTS = 50
SPEED = 5
class Plane:
def __init__(self):
self.dirs = []
self.mags = []
for i in range(N_POINTS):
x = degrees_to_radians(i)
self.dirs.append([math.sin(x), math.cos(x)])
self.mags.append(0)
self.color = [random.randint(100, 255), random.randint(100, 255), random.randint(100, 255)]
def compute(self):
for _ in range(SPEED):
index = random.randint(0, N_POINTS - 1)
offset = 1+random.random()
self.mags[index] += offset
if min(self.mags) > advmath.pythag([display.get_width(), display.get_height()]):
self.__init__()
def render(self):
points = []
for i in range(len(self.dirs)):
point = [self.dirs[i][0]*self.mags[i], self.dirs[i][1]*self.mags[i]]
points.append([(display.get_width() - point[0])/2, (display.get_height() - point[1])/2])
draw.polygon(self.color, points)
plane = Plane()
while True:
events.handle()
plane.compute()
plane.render()
display.refresh(refresh_rate=360)