var W=a.width,H=a.height,M=Math,Od=Object.defineProperty,OS=function(b='pSys'){var d=this;d.id=b,d.x=0,d.y=0,d.aB=[],d.nB=0};OS.prototype.addBody=function(b){b.pB=this;var d=new OB(b);d.update(),this.aB.push(d),this.nB+=1},OS.prototype.update=function(){for(var b,d=0;d<this.nB;d++)b=this.aB[d],b.update()};var OB=function(b){var d=this;return d.id=b.id,d.d=b.d,d.col=b.col,d.x=0,d.y=0,d.vx=0,d.vy=0,d.de=b.de,d.s=b.s,d.oR=b.oR,d.pB=b.pB,d};OB.prototype.update=function(){var b=this,d=b.de*M.PI/180;b.de+=b.s,b.vx=b.oR*M.cos(d),b.vy=b.oR*M.sin(d),null!=b.pB&&(b.x=b.vx+b.pB.x,b.y=b.vy+b.pB.y)};var pSys=new OS;pSys.x=.5*W,pSys.y=.5*H,pSys.addBody({id:'s',d:5,de:0,s:0,col:'#f36',oR:0,pB:null});for(var loop=40,i=0;i<loop;i+=1)pSys.addBody({id:'b'+i,d:5,de:45,s:0.1*loop-0.1*i,col:'#f36',oR:8*(i+1),pB:'s'});setInterval(()=>{c.fillStyle='#000',c.fillRect(0,0,W,H),pSys.update();for(var b,d=pSys.nB,e=0;e<d;e+=1)b=pSys.aB[e],c.beginPath(),c.arc(b.x,b.y,b.d,0,2*M.PI,!1),c.fillStyle=b.col,c.fill()},16);
var W = a.width,
H = a.height,
M = Math,
Od = Object.defineProperty;
/* OrbitalSystem */
var OrbitalSystem = function(){
var t = this;
t.x = 0;
t.y = 0;
t.allBodies = [];
t.numBodies = 0;
}
OrbitalSystem.prototype.addBody = function(vo) {
vo.parentBody = this;
var body = new OrbitalBody(vo);
body.update();
this.allBodies.push(body);
this.numBodies += 1;
}
OrbitalSystem.prototype.update = function(){
var body;
for(var i=0; i<this.numBodies; i++){
body = this.allBodies[i];
body.update();
}
}
/* OrbitalBody */
var OrbitalBody = function(vo){
var t = this;
t.id = vo.id;
t.d = vo.d;
t.col = vo.col;
t.x = 0;
t.y = 0;
t.vx = 0;
t.vy = 0;
t.degrees = vo.degrees;
t.speed = vo.speed;
t.orbitalRadius = vo.orbitalRadius;
t.parentBody = vo.parentBody;
return t;
}
OrbitalBody.prototype.update = function(){
var t = this,
angle = t.degrees * M.PI/180;
t.degrees += t.speed;
t.vx = t.orbitalRadius * M.cos(angle);
t.vy = t.orbitalRadius * M.sin(angle);
if(t.parentBody != null){
t.x = t.vx + t.parentBody.x;
t.y = t.vy + t.parentBody.y;
}
}
var pSys = new OrbitalSystem();
pSys.x = W * .5;
pSys.y = H * .5;
pSys.addBody({id:'s', d:5, degrees:0, speed:0, col:'#f36', orbitalRadius:0, parentBody:null});
for(var loop=40, i=0; i<loop; i+=1){
pSys.addBody({ id: 'b'+i,
d: 5,
degrees: 45,
speed: (loop*0.1) - (i*0.1),
col: '#f36',
orbitalRadius: 8*(i+1),
parentBody: 's'});
}
setInterval(function(){
// Clear everything
c.fillStyle = '#000';
c.fillRect(0,0,W,H);
pSys.update();
var planetaryBody;
for(var loop=pSys.numBodies, j=0; j<loop; j+=1) {
planetaryBody = pSys.allBodies[j];
c.beginPath();
c.arc(planetaryBody.x, planetaryBody.y, planetaryBody.d, 0, M.PI*2, false);
c.fillStyle = planetaryBody.col;
c.fill();
}
}, 16);