/** * A particle. Everything in this universe is a particle. * Nick Selvaggio * 12.02.09 **/ class Particle { PVector loc; PVector vel; PVector acc; float mass; color myColor; float t; //time. it keeps going. float lifespan; //its our destiny. //----------------------------------------------------- Particle(PVector location) { loc = location; acc = new PVector(); vel = new PVector(0,0); //initial velocity mass = 5; lifespan = random(350); myColor = someColor(); } //------------------------------------------------------- void render() { //output a sphere. //output a point. stroke(myColor,90); strokeWeight(6); //messing around. //curve(loc.x-vel.x, loc.y-vel.y, loc.x, loc.y, loc.x+vel.x, loc.y+vel.y, (loc.x-vel.x), (loc.x-vel.y)); line(loc.x, loc.y, (loc.x-vel.x), (loc.y-vel.y)); //point(loc.x, loc.y); smooth(); fill(0, 100); noStroke(); ellipse(loc.x, loc.y, mass, mass); } //------------------------------------------------------- void die() { //life is over... it was fun. //drop the particle off the screen using a gravitational force. //applyForce(new PVector(0, 9.8)); } //------------------------------------------------------- // Some getters. float getMass() { return mass; } PVector getLoc() { return loc; } //------------------------------------------------------- void checkWalls() { //lets check our boundaries. if(loc.x > width || loc.x < 0) { vel.x = -vel.x; } if(loc.y > height || loc.y < 0) { vel.y = -vel.y; } } //------------------------------------------------------- void lineTo(Particle p) { smooth(); stroke(255); line(loc.x, loc.y, p.loc.x, p.loc.y); } }