| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ ArrayList<ParticleSystem> systems; | |||
| 15 | 15 | void setup() { | |
| 16 | 16 | size(640, 360); | |
| 17 | 17 | systems = new ArrayList<ParticleSystem>(); | |
| 18 | - smooth(); | ||
| 19 | 18 | } | |
| 20 | 19 | ||
| 21 | 20 | void draw() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | // An ArrayList is used to manage the list of Particles | |
| 2 | 2 | // An Iterator is used to remove "dead" particles while iterating over the list | |
| 3 | - import java.util.Iterator; | ||
| 4 | 3 | ||
| 5 | 4 | class ParticleSystem { | |
| 6 | 5 | ||
@@ -15,14 +14,14 @@ class ParticleSystem { | |||
| 15 | 14 | } | |
| 16 | 15 | } | |
| 17 | 16 | ||
| 17 | + | ||
| 18 | 18 | void run() { | |
| 19 | - // Cycle through the ArrayList using Iterator, because we are deleting while iterating | ||
| 20 | - Iterator<Particle> it = particles.iterator(); | ||
| 21 | - while (it.hasNext()) { | ||
| 22 | - Particle p = it.next(); | ||
| 19 | + // Cycle through the ArrayList backwards, because we are deleting while iterating | ||
| 20 | + for (int i = particles.size()-1; i >= 0; i--) { | ||
| 21 | + Particle p = particles.get(i); | ||
| 23 | 22 | p.run(); | |
| 24 | 23 | if (p.isDead()) { | |
| 25 | - it.remove(); | ||
| 24 | + particles.remove(i); | ||
| 26 | 25 | } | |
| 27 | 26 | } | |
| 28 | 27 | } | |
@@ -32,7 +31,8 @@ class ParticleSystem { | |||
| 32 | 31 | // Add either a Particle or CrazyParticle to the system | |
| 33 | 32 | if (int(random(0, 2)) == 0) { | |
| 34 | 33 | p = new Particle(origin); | |
| 35 | - } else { | ||
| 34 | + } | ||
| 35 | + else { | ||
| 36 | 36 | p = new CrazyParticle(origin); | |
| 37 | 37 | } | |
| 38 | 38 | particles.add(p); | |
@@ -46,5 +46,5 @@ class ParticleSystem { | |||
| 46 | 46 | boolean dead() { | |
| 47 | 47 | return particles.isEmpty(); | |
| 48 | 48 | } | |
| 49 | + } | ||
| 49 | 50 | ||
| 50 | - } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments