class Particle { /* The way each of our particles work is familiar from the basic forces; location, velocity and acceleration. */ Vector3D loc; Vector3D vel; Vector3D accel; // Keep track of the size of our particle, and how long it's been // active float r; float timer; Particle(Vector3D loc_, Vector3D vel_, Vector3D accel_, float r_) { // save all of our constructor values loc = loc_.copy(); vel = vel_.copy(); accel = accel_.copy(); r = r_; // give each particle the same timer value timer = 100.0; } Particle(Vector3D loc_) { // save the constructor values loc = loc_.copy(); // create values for our other properties vel = new Vector3D(random(-1, 1), random(-4, 0), 0.0); accel = new Vector3D(0, 0.06, 0); r = 10.0; timer = 100.0; } void simulate() { update(); render(); } void update() { vel = vel.add(accel); loc = loc.add(vel); timer -= 1.0; } void render() { ellipseMode(CENTER); noStroke(); fill(32, 64, 128, timer); ellipse(loc.getX(), loc.getY(), r, r); } /* we only want our particles to 'live' for a certain amount of time. In this case our timer variable is counting down to 0. When it reaches 0 the particle system will remove it from action; the only way for the particle system to know if the particle is finished, is to check the isDead() method. */ boolean isDead() { if (timer <= 0.0) { return true; } else { return false; } } }