xxxxxxxxxx
31
let blackhole;
let planets = [];
let g = 0.4;
function setup() {
createCanvas(600, 600);
for (let i = 0; i < 5; i++) {
planets.push(new Planet(random(0.8, 2)*4, random(width), random(height)));
}
blackhole = new Blackhole();
}
function draw() {
background(255);
for (let i = 0; i < planets.length; i++) {
for (let j = 0; j < planets.length; j++) {
if (i != j) {
let force = planets[j].attract(planets[i]);
planets[i].applyForce(force);
}
}
let force = blackhole.attract(planets[i]);
planets[i].applyForce(force);
planets[i].update();
planets[i].show();
}
blackhole.show();
}