var w;
function setup(){
createCanvas(400, 200)
background(0)
w = new Walker
}
function draw(){
w.run()
}
class Walker {
constructor(){
// 位置向量
this.location = new p5.Vector(0 ,0);
// t
this.t = new p5.Vector(0 ,10000);
}
run(){
this.move(this.location, this.t)
this.show(this.location)
}
show(l){
noFill()
stroke(255, 255, 0)
// ellipse(this.x, this.y, 5, 5)
point(l.x, l.y)
}
move(l, t){
l.x += map(noise(t.x), 0,1, -1, 1 )
l.y += map(noise(t.y), 0,1, -1, 1 )
t.x += 0.01;
t.y += 0.01;
// 不要跑出去咯
l.x = constrain(l.x, 0, width);
l.y = constrain(l.y, 0, height);
}
}
console