sketch = p => {
let walker
p.setup = () => {
p.createCanvas(width, 600)
walker = walkerFactory()
p.background(13,15,5)
};
p.draw = () => {
walker.update()
walker.show()
if (walker.pos.x > width || walker.pos.x < 0) walker.pos.x = p.random(50, 400)
if (walker.pos.y > 600 || walker.pos.y < 0) walker.pos.y = p.random(400, 550)
}
function walkerFactory (x = 50, y = 550 ) {
return {
x,
y,
pos: p.createVector(x, y),
vel: p5.Vector.random2D().mult(p.random(3)),
update () {
this.pos.add(this.vel)
},
show () {
p.background(13,15,5)
p.stroke(222,61,131)
p.strokeWeight(8)
p.fill(228,189,11)
p.ellipse(this.pos.x, this.pos.y, 44)
}
}
}
}