xxxxxxxxxx
52
class Mover {
constructor() {
this.pos = createVector(random(width), random(height));
this.vel = createVector(0, 0);
this.r = random(4,18);
}
update() {
let mouse = createVector(mouseX, mouseY);
let dir = p5.Vector.sub(mouse, this.pos)
let wiggle = createVector(noise(), noise());
let d = dist(mouse.x, mouse.y, this.pos.x, this.pos.y)
dir.setMag(random(0.2, 0.4))
this.acc = dir;
this.vel.add(this.acc);
this.vel.limit(random(2.5, 6.5))
this.pos.add(this.vel);
}
show() {
noStroke();
fill(220);
circle(this.pos.x, this.pos.y, this.r);
}
lines() {
strokeWeight(2);
stroke(200, 40);
line(mouseX, mouseY, mouseX, this.pos.y)
line(mouseX, this.pos.y, this.pos.x, this.pos.y)
stroke(255, 0, 0)
line(mouseX, mouseY, this.pos.x, this.pos.y);
}
checkEdges() {
if (this.pos.x > width) {
this.pos.x = 0;
} else if (this.pos.x < 0) {
this.pos.x = width;
}
if (this.pos.y > height) {
this.pos.y = 0;
} else if (this.pos.y < 0) {
this.pos.y = height;
}
}
}