xxxxxxxxxx
35
class Walker {
constructor() {
this.pos = createVector(width/2, height/2);
}
show() {
fill(255);
stroke(255)
strokeWeight(8);
point(this.pos.x, this.pos.y);
}
update() {
this.vel = createVector(randomGaussian(0, 4), randomGaussian(0, 4));
if (this.pos.x > width || this.pos.x < 0) {
this.pos.x = this.pos.x
this.vel.x = this.vel.x * -1
} else if (this.pos.y > height || this.pos.y < 0) {
this.pos.y = this.pos.y
this.vel.y = this.vel.y * -1
}
this.pos.add(this.vel);
}
}
function setup() {
createCanvas(400, 400);
walker = new Walker();
}
function draw() {
background(20);
walker.update()
walker.show()
}