-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticles.py
71 lines (52 loc) · 1.82 KB
/
particles.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
try:
from traceback import format_exception
import random
import time
import pmma
import math
pmma.init(general_profile_application=True)
pmma.set_allow_anti_aliasing(False)
pmma.set_anti_aliasing_level(8)
canvas = pmma.Display()
canvas.create(1280, 720, full_screen=False, resizable=True)
events = pmma.Events()
N = 1000
s = int((canvas.get_width()**2 + canvas.get_height()**2)**0.5)
class Particle:
def __init__(self, n):
self.n = n
self.o = random.randint(500, s)
self.pixel = pmma.Pixel()
self.pixel.set_color([255, 255, 255])
self.color = pmma.ColorConverter()
def __del__(self):
self.pixel.quit()
def render(self, now_time):
x = (canvas.get_width() - (math.sin(now_time+self.n) * self.o))/2
y = (canvas.get_height() - (math.cos(now_time+self.n) * self.o))/2
#self.pixel.set_color(self.color.generate_color_from_perlin_noise(now_time/2))
self.pixel.set_position([x, y])
self.pixel.render()
particles = []
for i in range(N):
particles.append(Particle(i))
col = pmma.ColorConverter()
start = time.perf_counter()
now_time = 0
#pmma.targeted_profile_start()
while pmma.get_application_running():
canvas.clear()
events.handle()
for particle in particles:
particle.render(now_time)
pmma.compute()
canvas.refresh(refresh_rate=2000)
now_time = (time.perf_counter() - start)/5
#pmma.targeted_profile_end()
pmma.quit()
except Exception as error:
print("".join(
format_exception(
None,
error,
error.__traceback__)))