xxxxxxxxxx
40
//Creating walker class
class Walker{
constructor(){
//variables to store the walker's current coordinates and its previous coordinates
this.pos = createVector(width/2,height/2);
this.prev = this.pos.copy();
}
//function to create walker
spawn(){
strokeWeight(2);
//makes sure walker steps are connected by a line
line(this.pos.x,this.pos.y,this.prev.x,this.prev.y);
this.prev.set(this.pos);
}
//function to for new walker steps
update(){
// creates a random vector direction for new steps for walker
let direction = p5.Vector.random2D();
// controls randomness of long steps; less than 2%
let chance = random(100);
if (chance<2){
direction.mult(random(25,100));
}else{
direction.setMag(4);
//random color of walker
stroke(this.pos.x,map(this.pos.y,0,600,0,255),chance);
}
this.pos.add(direction);
}
}