-
Notifications
You must be signed in to change notification settings - Fork 2
/
of.particle.pd
60 lines (60 loc) · 2.66 KB
/
of.particle.pd
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
#N canvas 338 177 942 755 12;
#X msg 22 -29 bang;
#X msg 67 -29 add;
#X obj 234 6 loadbang;
#X obj 877 554 outlet;
#X obj 22 -78 inlet;
#X obj 22 -52 route reset add bang;
#X msg 113 -28 draw;
#X obj 22 849 ofelia f \; local particleSystem = a \; local ps = particleSystem.new()
\; function M.add() \; ps.addParticle() end \; function M.draw() ps.run()
end \;;
#X f 120;
#X obj 884 816 outlet;
#X obj 67 7 s \$0-part;
#X obj 53 825 r \$0-part;
#X obj 22 559 ofelia f -c12 \; local outlet = ofOutlet(this) \; local
particle = a \; function M.new(position) \; local o = ofTable() \;
o.origin = position \; o.particles = ofTable() \; function o.addParticle()
\; o.particles[#o.particles + 1] = particle.new(o.origin) outlet:outletList(1
\, ofTable(#o.particles)) \; end \; function o.run() \; for i = #o.particles
\, 1 \, -1 do \; local p = o.particles[i] \; p.run() \; if p.isDead()
then \; table.remove(o.particles \, i) outlet:outletList(1 \, ofTable(#o.particles))
end end end \; return o end \; return M \;;
#X f 120;
#X obj 22 31 ofelia f -c12 \$0-particle \; local outlet = ofOutlet(this)
\; local canvas = ofCanvas(this) \; local args = canvas:getArgs() \;
local size \, life \, pos \, vel \, accel \, color = 1 \, 100 \, ofVec3f()
\, ofVec3f(1 \, 1 \, 1) \, ofVec3f() \, ofColor(255 \, 255 \, 255)
\; \; function M.new(l) \; if args[1] == not nil then life = args[1]
end \; local o = ofTable() \; o.acceleration = accel \; o.velocity
= ofVec3f(ofRandom(-vel.x \, vel.x) \, ofRandom(-vel.y \, vel.y) \,
ofRandom(-vel.z \, vel.z)) \; o.position = pos o.lifespan = life *
2.55 o.size = size \; function o.run() \; o.update() o.display() end
\; function M.life(f) life = f end \; function M.size(f) size = f end
\; function M.color(l) color:set (table.unpack(l)) end \; function
M.acceleration(l) o.acceleration:set (table.unpack(l)) end \; function
M.position(l) pos:set (table.unpack(l)) end \; function M.velocity(l)
vel:set (table.unpack(l)) end \; \; function o.update() \; o.velocity
= o.velocity + o.acceleration \; o.position = o.position + o.velocity
\; o.lifespan = o.lifespan - 1 \; end \; function o.display() ofSetColor(color
\, o.lifespan * 2.55) \; ofPushMatrix() ofTranslate(o.position.x \,
o.position.y \, o.position.z) ofScale(o.size) outlet:outletBang(1)
ofPopMatrix() \; end \; function o.isDead() \; if o.lifespan < 0 then
\; return true \; else \; return false end end \; return o end \; return
M \;;
#X f 120;
#X connect 0 0 12 0;
#X connect 1 0 9 0;
#X connect 2 0 12 0;
#X connect 4 0 5 0;
#X connect 5 0 0 0;
#X connect 5 1 1 0;
#X connect 5 2 6 0;
#X connect 5 3 12 0;
#X connect 6 0 9 0;
#X connect 10 0 7 0;
#X connect 11 0 7 0;
#X connect 11 1 8 0;
#X connect 12 0 11 0;
#X connect 12 1 3 0;