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; float timerMax; // Keep track of the rendering image PImage img; Particle(Vector3D loc_, Vector3D vel_, Vector3D accel_, float r_, PImage img_) { // save all of our constructor values loc = loc_.copy(); vel = vel_.copy(); accel = accel_.copy(); r = r_; img = img_; // give each particle the same timer value timer = rand.getRandom(0, 200); timerMax = timer; } Particle(Vector3D loc_, PImage img_) { // save the constructor values loc = loc_.copy(); img = img_; // create values for our other properties float x = rand.getRandom(-2, 2); float y = rand.getRandom(-3, 0); vel = new Vector3D(x, y, 0.0); accel = new Vector3D(0, 0.0, 0); r = 10.0; timer = rand.getRandom(0, 150); timerMax = timer; } void addForce(Vector3D force_) { accel = accel.add(force_); } void simulate() { update(); render(); } void update() { vel = vel.add(accel); loc = loc.add(vel); timer -= 2.5; accel.setXYZ(0, 0, 0); } void render() { imageMode(CORNER); tint(255, (timer / timerMax) * 100.0); image(img, loc.getX(), loc.getY(), img.width, img.height); } /* 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; } } }