xxxxxxxxxx
42
let w;
function setup() {
createCanvas(560,390);
background(220);
w = new Walker();
}
function draw() {
w.step();
w.render();
}
class Walker {
constructor() {
this.x = width/2;
this.y = height/2;
}
render() {
stroke(63,63,147);
point(this.x,this.y);
}
step() {
//4 possible steps
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);
}
}