diff --git a/java/examples/Topics/Simulate/SmokeParticleSystem/Particle.pde b/java/examples/Topics/Simulate/SmokeParticleSystem/Particle.pde index a8802c2f2..3351e144c 100644 --- a/java/examples/Topics/Simulate/SmokeParticleSystem/Particle.pde +++ b/java/examples/Topics/Simulate/SmokeParticleSystem/Particle.pde @@ -10,8 +10,8 @@ class Particle { Particle(PVector l,PImage img_) { acc = new PVector(0,0); - float vx = (float) generator.nextGaussian()*0.3; - float vy = (float) generator.nextGaussian()*0.3 - 1.0; + float vx = randomGaussian()*0.3; + float vy = randomGaussian()*0.3 - 1.0; vel = new PVector(vx,vy); loc = l.get(); lifespan = 100.0; @@ -33,8 +33,8 @@ class Particle { void update() { vel.add(acc); loc.add(vel); - acc.mult(0); // clear Acceleration lifespan -= 2.5; + acc.mult(0); // clear Acceleration } // Method to display @@ -42,10 +42,14 @@ class Particle { imageMode(CENTER); tint(255,lifespan); image(img,loc.x,loc.y); + // Drawing a circle instead + // fill(255,lifespan); + // noStroke(); + // ellipse(loc.x,loc.y,img.width,img.height); } // Is the particle still useful? - boolean dead() { + boolean isDead() { if (lifespan <= 0.0) { return true; } else { @@ -54,6 +58,3 @@ class Particle { } } - - - diff --git a/java/examples/Topics/Simulate/SmokeParticleSystem/ParticleSystem.pde b/java/examples/Topics/Simulate/SmokeParticleSystem/ParticleSystem.pde index b0e2ed439..5c2d5bcab 100644 --- a/java/examples/Topics/Simulate/SmokeParticleSystem/ParticleSystem.pde +++ b/java/examples/Topics/Simulate/SmokeParticleSystem/ParticleSystem.pde @@ -4,25 +4,24 @@ class ParticleSystem { ArrayList particles; // An arraylist for all the particles - PVector origin; // An origin point for where particles are birthed + PVector origin; // An origin point for where particles are birthed PImage img; ParticleSystem(int num, PVector v, PImage img_) { particles = new ArrayList(); // Initialize the arraylist - origin = v.get(); // Store the origin point + origin = v.get(); // Store the origin point img = img_; for (int i = 0; i < num; i++) { - particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist + particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist } } void run() { - Iterator it = particles.iterator(); - while (it.hasNext()) { - Particle p = it.next(); + for (int i = particles.size()-1; i >= 0; i--) { + Particle p = particles.get(i); p.run(); - if (p.dead()) { - it.remove(); + if (p.isDead()) { + particles.remove(i); } } } @@ -40,19 +39,6 @@ class ParticleSystem { particles.add(new Particle(origin,img)); } - void addParticle(Particle p) { - particles.add(p); - } - - // A method to test if the particle system still has particles - boolean dead() { - if (particles.isEmpty()) { - return true; - } else { - return false; - } - } - } diff --git a/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde b/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde index 7941208a1..23be99484 100644 --- a/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde +++ b/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde @@ -11,14 +11,11 @@ /* @pjs preload="texture.png"; */ ParticleSystem ps; -Random generator; void setup() { size(640,360); - generator = new Random(); PImage img = loadImage("texture.png"); ps = new ParticleSystem(0,new PVector(width/2,height-60),img); - smooth(); } void draw() {