33 lines
580 B
JavaScript
33 lines
580 B
JavaScript
class Walker {
|
|
constructor(x = 0, y = 0) {
|
|
this.t = createVector(0, 10000)
|
|
this.pos = createVector(x, y)
|
|
}
|
|
|
|
step() {
|
|
let dx = map(noise(this.t.x), 0, 1, -1, 1)
|
|
let dy = map(noise(this.t.y), 0, 1, -1, 1)
|
|
|
|
this.pos.add(createVector(dx, dy))
|
|
this.t.add(createVector(0.01, 0.01))
|
|
}
|
|
|
|
draw() {
|
|
stroke(0)
|
|
point(this.pos)
|
|
}
|
|
}
|
|
|
|
let walker
|
|
|
|
function setup() {
|
|
createCanvas(640, 240)
|
|
background(255)
|
|
walker = new Walker(320, 120)
|
|
}
|
|
|
|
function draw() {
|
|
walker.step();
|
|
walker.draw();
|
|
}
|