class Mover {
constructor(p5) {
this.p5 = p5;
this.location = new P5.Vector(
this.p5.random(this.p5.width),
this.p5.random(this.p5.height)
);
this.velocity = new P5.Vector(this.p5.random(0.2), this.p5.random(0.2));
this.acceleration = P5.Vector.random2D().mult(p5.random(0.001, 1));
this.r = 10;
this.maxVelocity = 2;
}
update() {
this.edges();
this.velocity.add(this.acceleration);
this.velocity.limit(this.maxVelocity);
this.location.add(this.velocity);
}
edges() {
if (this.location.x >= this.p5.width - this.r) {
this.location.x = this.p5.width - this.r - 1;
this.velocity.mult(-1);
this.acceleration.set(0, 0);
}
if (this.location.x <= this.r) {
this.location.x = this.r;
this.velocity.mult(-1);
this.acceleration.set(0, 0);
}
if (this.location.y >= this.p5.height - this.r) {
this.location.y = this.p5.height - this.r;
this.velocity.mult(-1);
this.acceleration.set(0, 0);
}
if (this.location.y <= this.r) {
this.location.y = this.r;
this.velocity.mult(-1);
this.acceleration.set(0, 0);
}
}
display() {
this.p5.fill("black");
this.p5.circle(this.location.x, this.location.y, this.r / 2);
this.p5.noFill();
this.p5.circle(this.location.x, this.location.y, this.r * 2);
}
}