-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathparticles_emit.py
More file actions
57 lines (42 loc) · 1.19 KB
/
particles_emit.py
File metadata and controls
57 lines (42 loc) · 1.19 KB
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
from mewnala import *
import math
p = None
sphere = None
mat = None
frame = 0
def setup():
global p, sphere, mat
size(900, 700)
mode_3d()
sphere = Geometry.sphere(0.08, 8, 6)
capacity = 2000
p = Particles(
capacity=capacity,
attributes=[Attribute.position(), Attribute.color()],
)
# park unemitted slots far off-screen until the ring buffer fills.
pos_buf = p.buffer(Attribute.position())
pos_buf.write([1.0e6] * (capacity * 3))
color_buf = p.buffer(Attribute.color())
mat = Material.unlit(albedo=color_buf)
def draw():
global frame
camera_position(0.0, 4.0, 14.0)
camera_look_at(0.0, 0.0, 0.0)
background(15, 15, 20)
use_material(mat)
particles(p, sphere)
burst = 4
positions = []
colors = []
for k in range(burst):
i = frame * burst + k
t = i * 0.05
radius = 1.5 + min(t * 0.02, 3.0)
height = math.sin(t * 0.1) * 2.0
positions.extend([math.cos(t) * radius, height, math.sin(t) * radius])
c = hsva((i * 4.32) % 360.0, 0.85, 1.0)
colors.extend([c.r, c.g, c.b, 1.0])
p.emit(burst, position=positions, color=colors)
frame += 1
run()