// Dropping particles // Click the mouse to add obstacles // Daniel Shiffman // www.shiffman.net // Nov 2006 // Our Particle Class class Particle { float x; float y; float xspeed; float yspeed; float timer = 255; float r; Particle(float x_, float y_) { x = x_; y = y_; r = 4; float theta = random(PI,TWO_PI); float r = random(0.5,1); xspeed = r*cos(theta); yspeed = r*sin(theta); } void run() { x = x + xspeed; y = y + yspeed; timer-=0.5; } void gravity() { yspeed += 0.05; } void hitObstacle(Obstacle obs) { if (obs.contains(x,y)) { yspeed *= -0.5; y += yspeed; // give it a little extra kick } } void render() { fill(255,timer); noStroke(); ellipse(x,y,r,r); } boolean finished() { if (timer < 0) { return true; } else { return false; } } }