xxxxxxxxxx
70
function Particle(x,y){
this.pos = createVector(x,y);
this.vel = createVector();
this.acc = createVector();
this.size = 8;
this.maxSpeed = 4;
this.maxForce = 0.3;
}
Particle.prototype.findTarget = function(x,y){
this.target = createVector(x,y);
}
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.inVision = function(other){
var inVis = false;
var theta = this.getTheta();
}
Particle.prototype.getTheta = function(){
var theta = this.vel.heading() + PI/2;
return theta;
}
Particle.prototype.show = function(){
theta = this.getTheta();
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);
noFill();
arc(0,-this.size*10,-this.size*20,-this.size*23,PI,TWO_PI);
line(this.size*10,-this.size*10,-this.size*10,-this.size*10);
line(0,0,this.size*10,-this.size*10);
line(0,0,-this.size*10,-this.size*10);
pop();
}