xxxxxxxxxx
40
let walker;
function setup() {
createCanvas(640, 360);
walker = new Walker();
background(127);
}
function draw() {
walker.step();
walker.render();
}
class Walker {
constructor() {
this.x = width / 2;
this.y = height / 2;
}
render() {
stroke(1000565);
point(this.x, this.y);
}
step() {
let choice = random(1);
if (choice < 0.2) {
this.x++;
} else if (choice < 0.5) {
this.x--;
} else if (choice < 0.7) {
this.y++;
} else if (choice < 1) {
this.y--;
}
this.x = constrain(this.x, 0, width - 1);
this.y = constrain(this.y, 0, height - 1);
}
}