-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircuits.py
85 lines (58 loc) · 1.96 KB
/
circuits.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
import pmma
import random
import time
pmma.init()
display = pmma.Display()
display.create()
events = pmma.Events()
registry = pmma.Registry
color = pmma.Color()
class Point:
def __init__(self):
self.x = random.randint(0, display.get_width())
self.y = random.randint(0, display.get_height())
self.noise = pmma.Perlin()
self.circle = pmma.Circle()
self.circle.set_radius(3)
def compute(self):
x_value = self.noise.generate_1D_perlin_noise(now_time/10 + self.x)
y_value = self.noise.generate_1D_perlin_noise(now_time/10 + self.y)
if x_value > 0.5:
self.x += 1
elif x_value < -0.5:
self.x -= 1
if y_value > 0.5:
self.y += 1
elif y_value < -0.5:
self.y -= 1
if self.x < 0:
self.x = random.randint(0, display.get_width())
self.y = random.randint(0, display.get_height())
elif self.x > display.get_width():
self.x = random.randint(0, display.get_width())
self.y = random.randint(0, display.get_height())
if self.y < 0:
self.x = random.randint(0, display.get_width())
self.y = random.randint(0, display.get_height())
elif self.y > display.get_height():
self.x = random.randint(0, display.get_width())
self.y = random.randint(0, display.get_height())
def render(self, color):
self.compute()
self.circle.set_center([self.x, self.y])
self.circle.set_color(color)
self.circle.draw()
N = 720
points = [Point() for _ in range(N)]
start = time.perf_counter()
now_time = 0
while registry.running:
color_value = color.generate_color_from_perlin_noise(now_time/10, format=pmma.Constants.RGB)
display.clear()
events.handle()
for point in points:
point.render(color_value)
pmma.compute()
display.refresh()
now_time = time.perf_counter() - start
pmma.quit()