xxxxxxxxxx
31
let G = 6.6743e-11;
let a;
let m1 = 8;
let b;
let m2 = 10;
function setup() {
a = createVector(random(0, width), random(0, height));
b = createVector(random(0, width), random(0, height));
createCanvas(400, 400);
}
function draw() {
background(0);
let force = p5.Vector.sub(b, a);
let distance = force.mag();
force.setMag(G * ((m1 * m2) / (distance * distance)));
a.add(force);
force = p5.Vector.sub(a, b);
distance = force.mag();
force.setMag(G * ((m1 * m2) / (distance * distance)));
b.add(force);
circle(a.x, a.y, 80);
circle(b.x, b.y, 100);
b.x = mouseX;
b.y = mouseY;
}