// A simple Particle class class Particle { Vector3D loc; Vector3D vel; Vector3D acc; float startRadius=10; float r; float timer; color _c; color startColor; public int lifeTime=220; float clearValue=12; int redDec; int blueDec; int greenDec; // Another constructor (the one we are using here) Particle(Vector3D l, color c, int d, float a) { lifeTime=d; acc = new Vector3D(random(-.1*a,.1*a),random(-.05*a,.05*a),0 ); //This determines how fast it falls or shoots out float seed=random(-4,1); vel = new Vector3D(cos(seed),sin(seed),0); //This determines what direction it initially spreads in loc = l.copy(); startRadius = random (2,maxRadius); timer = lifeTime; _c=c; startColor=_c; } void run() { //Color redDec=int((255-red(startColor)) * random(1,timer)/lifeTime)+redOffset; blueDec=int((255-blue(startColor)) * random(1,timer)/lifeTime)+blueOffset; greenDec=int((255-green(startColor)) * random(1,timer)/lifeTime)+greenOffset; //Greyscale // redDec=int((255-red(startColor)) * random(1,timer)); // blueDec=int((255-blue(startColor)) * random(1,timer)); // greenDec=int((255-green(startColor)) * random(1,timer)); r=startRadius*(timer/lifeTime); clearValue=10; clear(); update(); render(); } // Method to update location void update() { vel.add(acc); loc.add(vel); timer--; } //Clears previous render void clear() { if (clearTrail==false) return; noStroke(); fill(0,clearValue); ellipse(loc.x,loc.y,r,r); } // Method to display void render() { _c=color(red(startColor)+redDec,green(startColor)+greenDec,blue(startColor)+blueDec); stroke(0,10); ellipseMode(CENTER); fill(_c,timer/3); ellipse(loc.x,loc.y,r,r); } // Is the particle still useful? boolean dead() { if (timer <= 0.0) { return true; } else { return false; } } }