xxxxxxxxxx
28
class Blackhole {
constructor(x, y, m) {
this.pos = createVector(x, y);
this.mass = m;
this.rs = (2 * G * this.mass) / (c * c);
}
pull(photon) {
const force = p5.Vector.sub(this.pos, photon.pos);
const r = force.mag();
const fg = (G * this.mass) / (r * r);
force.setMag(fg);
photon.vel.add(force);
photon.vel.setMag(c);
if (r < this.rs) {
photon.stop();
}
}
show() {
ellipseMode(RADIUS);
fill(0, 0, 0);
stroke(35);
strokeWeight(10);
ellipse(this.pos.x, this.pos.y, this.rs);
}
}