xxxxxxxxxx
53
class Walker {
constructor(x, y) {
this.x = x;
this.y = y;
this.speed = random(1, 5);
}
display() {
stroke("black");
point(this.x, this.y);
}
step() {
const x= random(1);
const y= random(1);
const mouseYDir = mouseY > this.x ? this.speed : -this.speed;
if (x < 0.5) {
this.x += mouseX > this.x ? this.speed : -this.speed;
} else if (x < 0.66) {
this.x += this.speed;
} else if (x < 0.82) {
this.x -= this.speed;
}
if (y < 0.5) {
this.y += mouseY > this.y ? this.speed : -this.speed;
} else if (y < 0.66) {
this.y += this.speed;
} else if (y < 0.82) {
this.y -= this.speed;
}
// this.y += stepY;
}
}
let walkers;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(60);
strokeWeight(2);
walkers = [
Array(100).fill(0).map(x => new Walker(random(width), random(height)))];
}
function draw() {
walkers.forEach(w => {
w.step();
w.display();
})
}