mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
37 lines
641 B
Plaintext
37 lines
641 B
Plaintext
// The Nature of Code
|
|
// Daniel Shiffman
|
|
// http://natureofcode.com
|
|
|
|
class ParticleSystem {
|
|
ArrayList<Particle> particles;
|
|
PVector origin;
|
|
|
|
ParticleSystem(PVector location) {
|
|
origin = location.get();
|
|
particles = new ArrayList<Particle>();
|
|
}
|
|
|
|
void addParticle() {
|
|
float r = random(1);
|
|
if (r < 0.5) {
|
|
particles.add(new Particle(origin));
|
|
}
|
|
else {
|
|
particles.add(new ParticleChild(origin));
|
|
}
|
|
}
|
|
|
|
void run() {
|
|
for (int i = particles.size()-1; i >= 0; i--) {
|
|
Particle p = particles.get(i);
|
|
p.run();
|
|
if (p.isDead()) {
|
|
particles.remove(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|