xxxxxxxxxx
40
class Walker {
constructor() {
this.x = width / 2;
this.y = height / 2;
this.history = [];
// this.pos = createVector(width/2,height/2);
}
render() {
stroke(0);
point(this.x, this.y);
for (let i = 0; i < this.history.length; i++) {
point(this.history[i].x, this.history[i].y);
}
}
step() {
let choice = floor(random(4));
if (choice === 0) {
this.x++;
} else if (choice == 1) {
this.x--;
} else if (choice == 2) {
this.y++;
} else {
this.y--;
}
this.x = constrain(this.x, 0, width - 1);
this.y = constrain(this.y, 0, height - 1);
for (let i = 0; i < this.history.length; i++) {
this.history[i].x += 0.2;
}
let v = createVector(this.x, this.y);
this.history.push(v);
}
}