xxxxxxxxxx
64
let planets = []
let planetNum = 9
//let maxSpeed = 5
let sunMass = 15
let maxMass = sunMass / 3
function setup() {
createCanvas(windowHeight,windowHeight);
planets.push(new Planet(0,width/2,height/2,sunMass,true))
// planets.push(new Planet(1,width/4,height/2,10,0,2.14,false))
// planets.push(new Planet(2,(5*width)/8,height/2,5,0,-3,false))
let planetCount = 0
for (i = 1; planetCount < planetNum; i++){
let xCoord = random(0,(windowHeight/2)-(1.5 * sunMass))
let mass = random(1,maxMass)
let overlap = false
for (let o of planets) {
if (dist(xCoord,windowHeight/2,o.location.x,o.location.y) < mass + o.radius) {
overlap = true
}
}
if (overlap == false) {
planets.push(new Planet(i,xCoord,windowHeight/2,mass,false))
planetCount += 1
}
}
// planets.push(new Planet(1,438, 634.8799511602067,5.70112304601356,0,0.8855073969757914,false))
// //planets.push(new Planet(1,438, 634.8799511602067,5.70112304601356,1.5271233409245784,0.8855073969757914,false))
// planets.push(new Planet(0,windowWidth/2,windowHeight/2,20.38958352861241,0,0,true))
//console.log(planets)
}
function draw() {
background(10);
noFill()
for (let p of planets){
for (let o of planets){
if (p.static == false && o.static == true){
p.gravity(o)
}
}
p.update()
p.draw()
}
// noLoop()
if (keyIsDown(LEFT_ARROW)){
planets[0].location.x -= 1
}
if (keyIsDown(RIGHT_ARROW)){
planets[0].location.x += 1
}
if (keyIsDown(UP_ARROW)){
planets[0].location.y -= 1
}
if (keyIsDown(DOWN_ARROW)){
planets[0].location.y += 1
}
}