import processing.core.PApplet;
import processing.core.PVector;

// Particles + Forces
// Daniel Shiffman <http://www.shiffman.net>

// A simple Particle class
// Incorporates forces code

public class Particle {
  PVector loc;
  PVector vel;
  PVector acc;
  float mass;
  float r;
  float timer;
  float maxspeed;
  PApplet p;
  int color;

  // Another constructor (the one we are using here)
  Particle(PApplet _p, PVector l, int _c) {
	p = _p;
    acc = new PVector(0,0);
    vel = new PVector(p.random(-1,1),p.random(-1,1));
    loc = l.get();
    r = 20.0f;
    timer = 80.0f;
    maxspeed = 2.1f;
    mass = 1.0f;
    color =_c;
  }


  void run() {
    update();
    render();
  }

  // Method to update location
  void update() {
    vel.add(acc);
    vel.limit(maxspeed);
    loc.add(vel);
    acc.mult(0);
    timer -= 0.5;
  }
  
   void applyForce(PVector force) {
    //float mass = 1; // We aren't bothering with mass here
    force.div(mass);
    acc.add(force);
  }


  // Method to display
  void render() {
    p.ellipseMode(p.CENTER);
    p.noStroke();
//    p.stroke(0,timer);
    p.fill(color,timer*1.0f);
    p.ellipse(loc.x,loc.y,r,r);
    
    // lets do a bit of a glow in the center
    // using the additive blending from openGL
    for(int i=2;i<r;i+=3){
      p.ellipse(loc.x,loc.y,r-i,r-i);
    }
  }
  
  // Is the particle still useful?
  boolean dead() {
    if (timer <= 0.0) {
      return true;
    } else {
      return false;
    }
  }


  public PVector getLoc() {
	  return loc;
  }


  public float getMass() {
	  return mass;
  }
}
