xxxxxxxxxx
let w;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(120);
background(250);
w = new Walker();
}
function draw() {
w.walk();
w.display();
}
class Walker {
constructor() {
this.x = random(width);
this.y = random(height);
}
walk() {
var r = random([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
if (r == 0) {
var mx = mouseX;
var my = mouseY;
if(mouseX - this.x > 0) this.x+=1;
else if(mouseX - this.x < 0) this.x -= 1;
if(mouseY - this.y > 0) this.y+=1;
else if(mouseY - this.y < 0) this.y -= 1;
} else{
var xStep = random(-1, 1);
var yStep = random(-1, 1);
this.x += xStep;
this.y += yStep;
}
}
display() {
strokeWeight(3);
point(this.x, this.y);
}
}