-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParticleSystem.pde
executable file
·48 lines (40 loc) · 1.01 KB
/
ParticleSystem.pde
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
class ParticleSystem {
ArrayList<Particle> particles;
ParticleSystem() {
particles = new ArrayList<Particle>();
}
void run() {
if (shapeControl) {
if (emitControl) {
particles.add(new circleParticle(new PVector(random(0, width), -20)));
} else {
particles.add(new circleParticle(new PVector(XPosControl, YPosControl)));
}
} else {
if (emitControl) {
particles.add(new rectParticle(new PVector(random(0, width), -20)));
} else {
particles.add(new rectParticle(new PVector(XPosControl, YPosControl)));
}
}
Iterator<Particle> it = particles.iterator();
while (it.hasNext ()) {
Particle iP = it.next();
iP.run();
if (iP.isDead()) {
it.remove();
}
}
}
void applyForce(PVector f) {
for (Particle p : particles) {
p.applyForce(f);
}
}
void applyObstruction(Obstacle ob) {
for (Particle p : particles) {
PVector f = ob.repelv2(p);
p.applyForce(f);
}
}
}