mirror of
https://github.com/processing/processing4.git
synced 2026-01-31 12:21:07 +01:00
moving the OpenGL examples to the core
This commit is contained in:
36
java/examples/OpenGL/Advanced/Particles/ParticleSystem.pde
Normal file
36
java/examples/OpenGL/Advanced/Particles/ParticleSystem.pde
Normal file
@@ -0,0 +1,36 @@
|
||||
class ParticleSystem {
|
||||
ArrayList<Particle> particles;
|
||||
|
||||
PShape particleShape;
|
||||
|
||||
ParticleSystem(int n) {
|
||||
particles = new ArrayList<Particle>();
|
||||
particleShape = createShape(PShape.GROUP);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
Particle p = new Particle();
|
||||
particles.add(p);
|
||||
particleShape.addChild(p.getShape());
|
||||
}
|
||||
}
|
||||
|
||||
void update() {
|
||||
for (Particle p : particles) {
|
||||
p.update();
|
||||
}
|
||||
}
|
||||
|
||||
void setEmitter(float x, float y) {
|
||||
for (Particle p : particles) {
|
||||
if (p.isDead()) {
|
||||
p.rebirth(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
|
||||
shape(particleShape);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user