Files
processing4/java/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystem.pde
2012-05-22 02:05:57 +00:00

44 lines
919 B
Plaintext

// The Particle System
class ParticleSystem {
// It's just an ArrayList of particle objects
ArrayList<Particle> particles;
// The PShape to group all the particle PShapes
PShape particleShape;
ParticleSystem(int n) {
particles = new ArrayList<Particle>();
// The PShape is a group
particleShape = createShape(GROUP);
// Make all the Particles
for (int i = 0; i < n; i++) {
Particle p = new Particle();
particles.add(p);
// Each particle's PShape gets added to the System PShape
particleShape.addChild(p.getShape());
}
}
void update() {
for (Particle p : particles) {
p.update();
}
}
void setEmitter(float x, float y) {
for (Particle p : particles) {
// Each particle gets reborn at the emitter location
if (p.isDead()) {
p.rebirth(x, y);
}
}
}
void display() {
shape(particleShape);
}
}