xxxxxxxxxx
35
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() {
//Arbitrary random value between -1.0 and 1.0
let stepx = random(-1, 1); //yields any floating point number between -1.0 and 1.0
let stepy = random(-1, 1); //yields any floating point number between -1.0 and 1.0
this.x += stepx;
this.y += stepy;
this.x = constrain(this.x,0,width-1);
this.y = constrain(this.y,0,height-1);
}
}