xxxxxxxxxx
61
function Particle(x,y,s){
this.pos = createVector(x,y);
this.vel = createVector();
this.acc = createVector();
this.size = s;
//this.maxSpeed = -s+11;
//this.maxSpeed = 4;
this.maxForce = -1*(s/8)+6.5;
}
Particle.prototype.findTarget = function(x,y){
this.target = createVector(x,y);
}
Particle.prototype.clearEffects = function(){
this.maxSpeed = -this.size + 11;
}
Particle.prototype.effect = function(){
this.maxSpeed = 1;
}
Particle.prototype.behaviors = function(){
var arrive = this.arrive(this.target);
arrive.mult(0.3);
this.acc.add(arrive);
}
Particle.prototype.arrive = function(t){
var dir = p5.Vector.sub(t,this.pos);
var d = dir.mag();
var speed = this.maxSpeed;
if (d < 100){
speed = map(d, 0, 100, 0, this.maxSpeed);
}
dir.setMag(speed);
var steer = p5.Vector.sub(dir,this.vel);
steer.limit(this.maxForce);
return steer;
}
Particle.prototype.update = function(){
this.pos.add(this.vel);
this.vel.add(this.acc);
this.acc.mult(0);
}
Particle.prototype.show = function(){
var theta = this.vel.heading() + PI/2;
fill(175);
stroke(0);
push();
translate(this.pos.x,this.pos.y);
rotate(theta);
beginShape();
vertex(0, -this.size*2);
vertex(-this.size, this.size*2);
vertex(this.size, this.size*2);
endShape(CLOSE);
pop();
}