xxxxxxxxxx
57
class Mover{
constructor(x, y, index){
this.index = index;
this.cpos = createVector(x, y);
this.npos = createVector(x, y);
this.vel = createVector(0, -1);
// this.vel.setHeading(-PI);
this.turn = createVector(1, 0);
this.wiggle = createVector(0,1);
this.wiggle.setMag(1);
this.xoff = 0.0001;
this.tav = -PI;
this.tat = 0.001;
this.taw = 0;
this.i = 0;
this.col = color(cols[this.index % cols.length])
}
update(){
this.i++
if(this.i > 1000){
// this.cpos.x = random(width);
// this.cpos.y = random(height);
this.i = 0;
}
this.xoff = this.xoff + 0.0001;
// this.vel.setHeading(noise(this.cpos.x / 20, this.cpos.y / 20, this.xoff) * (8 * PI));
this.turn.setHeading(noise(this.cpos.x / 1000, this.cpos.y / 1000, this.xoff) * (8 * PI))
this.turn.setMag(noise(this.cpos.x / 80, this.cpos.y / 80, this.xoff) * 2);
if(this.turn.mag() > 1) this.turn.setMag(this.turn.mag() - 1);
if(this.turn.mag() < 1) this.turn.setMag(this.turn.mag() * -1);
this.vel.add(this.turn);
this.vel.setMag(noise(this.cpos.x, this.cpos.y, this.xoff) * 2);
this.npos = p5.Vector.add(this.cpos, this.vel);
// this.col.setAlpha(2);
stroke(this.col);
strokeWeight(1);
line(this.cpos.x, this.cpos.y, this.npos.x, this.npos.y);
this.cpos.add(this.vel);
if(this.cpos.x > width) {
this.cpos.x = random(width);
this.cpos.y = random(height);
}
if(this.cpos.y > height){
this.cpos.x = random(width);
this.cpos.y = random(height);
}
if(this.cpos.x < 0){
this.cpos.x = random(width);
this.cpos.y = random(height);
}
if(this.cpos.y < 0){
this.cpos.x = random(width);
this.cpos.y = random(height);
}
}
}