Skip to content

Commit 5c4bce0

Browse files
author
Yong Bakos
committed
Incorporating random CrazyParticle addition and refactoring logic in dead.
1 parent 1609eb2 commit 5c4bce0

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

java/examples/Topics/Simulate/MultipleParticleSystems/ParticleSystem.pde

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ParticleSystem {
1616
}
1717

1818
void run() {
19-
// Cycle through the ArrayList using Iterator we are deleting
19+
// Cycle through the ArrayList using Iterator, because we are deleting while iterating
2020
Iterator<Particle> it = particles.iterator();
2121
while (it.hasNext()) {
2222
Particle p = it.next();
@@ -28,7 +28,14 @@ class ParticleSystem {
2828
}
2929

3030
void addParticle() {
31-
particles.add(new Particle(origin));
31+
Particle p;
32+
// Add either a Particle or CrazyParticle to the system
33+
if (int(random(0, 2)) == 0) {
34+
p = new Particle(origin);
35+
} else {
36+
p = new CrazyParticle(origin);
37+
}
38+
particles.add(p);
3239
}
3340

3441
void addParticle(Particle p) {
@@ -37,11 +44,7 @@ class ParticleSystem {
3744

3845
// A method to test if the particle system still has particles
3946
boolean dead() {
40-
if (particles.isEmpty()) {
41-
return true;
42-
} else {
43-
return false;
44-
}
47+
return particles.isEmpty();
4548
}
4649

4750
}

0 commit comments

Comments
 (0)