Current File : /home/jeshor13/11bsouth.com/Particles/Particle.js
var Particle = function  (position,mass) {
  this.position = position.copy();
  this.velocity = createVector((random(-12,12)/(mass/4)),(random(-12,12)/(mass/4)));
  this.acceleration = createVector();
  this.mass = mass


Particle.prototype.applyForce = function(f) { // f is a variable, which just points to a space in memorey 
  this.acceleration.add(p5.Vector.div(f, this.mass)); // conserves gravity and makes sure its the same 
}
Particle.prototype.update = function () {
  this.position.add(this.velocity);
  this.velocity.add(this.acceleration);
  this.acceleration.mult(0);
  
}

Particle.prototype.render = function(){
  noStroke()
  fill(0,0,255,80)
  ellipse(this.position.x,this.position.y,this.mass, this.mass);
}

Particle.prototype.isDead = function () {
  return (this.position.y > height|| this.position.x > width || this.position.x < 0)
}

 // Bounce off window
  Particle.prototype.checkEdges = function() {
    if (this.position.y > height) {
      this.velocity.y *= -0.9; 
      this.position.y = height;
    };
     if (this.position.y <0 ) {
      this.velocity.y *= -0.9;  
      this.position.y = 0;
    }; 
     if (this.position.x > width) {
      this.velocity.x *= -0.9; 
      this.position.x = width;
    }; 
    if (this.position.x < 0) {
      this.velocity.x *= -0.9;  
      this.position.x = 0;
    };
    if (this.velocity > 12) {
      this.velocity = 12
    };
  };
}