33 lines
468 B
JavaScript
33 lines
468 B
JavaScript
class Walker {
|
|
constructor(x = 0, y = 0) {
|
|
this.x = x
|
|
this.y = y
|
|
}
|
|
|
|
step() {
|
|
let dx = randomGaussian();
|
|
let dy = randomGaussian();
|
|
|
|
this.x += dx
|
|
this.y += dy
|
|
}
|
|
|
|
draw() {
|
|
stroke(0)
|
|
point(this.x, this.y)
|
|
}
|
|
}
|
|
|
|
let walker
|
|
|
|
function setup() {
|
|
createCanvas(640, 240)
|
|
background(255)
|
|
walker = new Walker(320, 120)
|
|
}
|
|
|
|
function draw() {
|
|
walker.step();
|
|
walker.draw();
|
|
}
|