class Particle {

  PVector velocity;
  PVector orgVel;
  float lifespan = 255;
  float speed;
  
  PShape part;
  float partSize;
  
  PVector gravity = new PVector(0,0.1);


  Particle() {
    partSize = random(10,60);
    part = createShape();
    part.beginShape(QUAD);
    part.noStroke();
    part.texture(sprite);
    part.normal(0, 0, 1);
    part.vertex(-partSize/2, -partSize/2, 0, 0);
    part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
    part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
    part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
    part.endShape();
    speed = random(0.5,2);
    rebirth(width/2,height/2);
    lifespan = random(255);
  }

  PShape getShape() {
    return part;
  }
  
  void rebirth(float x, float y) {
    float a = random(TWO_PI);
    speed = random(0.5,2);
    velocity = new PVector(cos(a), sin(a));
    velocity.mult(speed);
    orgVel = velocity;
    lifespan = 255;   
    part.resetMatrix();
    part.translate(x, y); 
  }
  
  boolean isDead() {
    if (lifespan < 0) {
     return true;
    } else {
     return false;
    } 
  }
  
  void updateVelocity(){
    velocity = orgVel;
    velocity.mult(speed);
    orgVel = velocity;
   // velocity.mult(speed);
  }

  public void update() {
    lifespan = lifespan - 1;
    //velocity.add(gravity);
    part.setTint(color(255,lifespan));
    part.translate(velocity.x, velocity.y);
  }
}