xxxxxxxxxx
38
class Mover {
constructor(x, y, m) {
this.pos = createVector(x, y);
this.vel = p5.Vector.random2D();
this.vel.mult(5);
this.acc = createVector(0, 0);
this.mass = m;
}
//applies force proportional to the mover's mass
applyForce(force) {
let f = p5.Vector.div(force, this.mass);
this.acc.add(f);
}
update() {
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.set(0, 0);
}
show() {
//uncomment if you want a more colorful design
stroke(random(255),random(255),random(255), 40)
// stroke(255,40);
strokeWeight(10);
//draws lines from movers to attractor to create unique design
line(this.pos.x, this.pos.y,attractor.pos.x, attractor.pos.y)
}
}