nodes = {
return parseBodies(solarSystem);
function parseBodies(bodies, parentMass = 0, posOffset = [0,0], velocityOffset = [0,0]) {
return [].concat(...bodies.map(body => {
const ang = (body.phase || (Math.random() * 360)) * Math.PI/180,
x = posOffset[0] + au(body.distance) * Math.sin(ang),
y = posOffset[1] - au(body.distance) * Math.cos(ang),
relVelocity = (body.distance ? Math.sqrt(pxG * parentMass / au(body.distance)): 0) * (body.factorV || 1),
vx = velocityOffset[0] + relVelocity * Math.cos(ang),
vy = velocityOffset[1] + relVelocity * Math.sin(ang);
return [{
name: body.name,
symbol: body.symbol || null,
color: body.color || 'darkgrey',
r: au(body.r || Math.cbrt(body.mass)),
mass: body.mass,
x: x,
y: y,
vx: vx,
vy: vy,
trail: []
},
...parseBodies(body.satellites || [], body.mass, [x,y], [vx,vy])
]
}));
}
}