xxxxxxxxxx
48
class Walker {
constructor(){
this.x = width/2
this.y = height/2
}
display(){
stroke(0);
point(this.x, this.y);
}
walk(){
let steps = randomGaussian(5, 2); // normal distribution steps
let dirs = [-1, 0, 1]
// tendenciando a andar na direçaõ do mouse
let walkXmouse = mouseX >= this.x ? mouseX === this.x ? random(dirs) : 1 : -1
let walkYmouse = mouseY >= this.y ? mouseY === this.y ? random(dirs) : 1 : -1
let rand = random(1)
if(rand < 0.5){
// com distribuicao normal
this.x += walkXmouse * steps
this.y += walkYmouse * steps
}
else{
// com distribuicao normal
this.x += random(dirs) * steps
this.y += random(dirs) * steps
}
}
}
function setup() {
createCanvas(400, 400);
background(220);
w = new Walker()
}
function draw() {
w.walk()
w.display()
}