diff --git a/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde b/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde index 82ddbbd..925a381 100644 --- a/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde +++ b/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde @@ -6,10 +6,10 @@ ParticleSystem ps; - PImage img; void setup() { + size(800, 200, P2D); // Create an alpha masked image to be applied as the particle's texture @@ -17,9 +17,15 @@ void setup() { ps = new ParticleSystem(0, new PVector(width/2, 50)); smooth(); + } -void draw() { - +void draw() { + blendMode(ADD); + background(0); + ps.run(); + for (int i = 0; i < 10; i++) { + ps.addParticle(); + } } diff --git a/NOC_4_09_AdditiveBlending/ParticleSystem.pde b/NOC_4_09_AdditiveBlending/ParticleSystem.pde index 4c945d5..73a07f2 100644 --- a/NOC_4_09_AdditiveBlending/ParticleSystem.pde +++ b/NOC_4_09_AdditiveBlending/ParticleSystem.pde @@ -10,13 +10,25 @@ class ParticleSystem { ArrayList particles; // An arraylist for all the particles PVector origin; // An origin point for where particles are birthed - PImage tex; -ParticleSystem(int num, PVector v) { -} + ParticleSystem(int num, PVector v) { + particles = new ArrayList(); // Initialize the arraylist + origin = v.get(); // Store the origin point + for (int i = 0; i < num; i++) { + particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist + } + } void run() { + Iterator it = particles.iterator(); + while (it.hasNext()) { + Particle p = it.next(); + p.run(); + if (p.dead()) { + it.remove(); + } + } } void addParticle() { @@ -36,5 +48,5 @@ ParticleSystem(int num, PVector v) { return false; } } - } +