From 0d6af3584213c76da4b7456035d021df830e520c Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Thu, 21 Feb 2013 18:55:53 -0700 Subject: [PATCH] Incorporating random CrazyParticle addition and refactoring logic in dead. --- .../MultipleParticleSystems/ParticleSystem.pde | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/java/examples/Topics/Simulate/MultipleParticleSystems/ParticleSystem.pde b/java/examples/Topics/Simulate/MultipleParticleSystems/ParticleSystem.pde index d6a3bed0a..d387e8444 100644 --- a/java/examples/Topics/Simulate/MultipleParticleSystems/ParticleSystem.pde +++ b/java/examples/Topics/Simulate/MultipleParticleSystems/ParticleSystem.pde @@ -16,7 +16,7 @@ class ParticleSystem { } void run() { - // Cycle through the ArrayList using Iterator we are deleting + // Cycle through the ArrayList using Iterator, because we are deleting while iterating Iterator it = particles.iterator(); while (it.hasNext()) { Particle p = it.next(); @@ -28,7 +28,14 @@ class ParticleSystem { } void addParticle() { - particles.add(new Particle(origin)); + Particle p; + // Add either a Particle or CrazyParticle to the system + if (int(random(0, 2)) == 0) { + p = new Particle(origin); + } else { + p = new CrazyParticle(origin); + } + particles.add(p); } void addParticle(Particle p) { @@ -37,11 +44,7 @@ class ParticleSystem { // A method to test if the particle system still has particles boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } + return particles.isEmpty(); } } \ No newline at end of file