function drawPlanets(context, centerX, centerY, orbitDistance, planetCount, angleShift) {
context.save(); // save the context before any transform.
context.translate(centerX, centerY); // move to the center
// !!!! Only change is here !!!!
context.rotate(angleShift || 0 );
var angle = 2 * Math.PI / planetCount; // angle between two planets
for (var i = 0; i < planetCount; i++) {
drawPlanet(context, orbitDistance);
context.rotate(angle);
}
context.restore(); // restore to previous state
}
// draw a planet in the current context, that is centered
// and already oriented towards the planet.
function drawPlanet(context, distance) {
drawCircle(context, distance, 0, planetsRadius);
}
function drawCircle(context, x, y, radius, fill) {
context.fillStyle = fill || '#ADB';
context.beginPath();
context.arc(x, 0, radius, 0, 2 * Math.PI);
context.fill();
}
function drawScene() {
context.clearRect(0, 0, cv.width, cv.height);
drawPlanets(context, sunPosition.x, sunPosition.y, planetsOrbit, planetCount, (Date.now() - startTime ) / 1000);
}
var sunRadius = 80;
var planetsOrbit = 160;
var planetsRadius = 20;
var planetCount = 8;
var sunPosition = {
x: 200,
y: 200
};
// boilerPlate
var context = cv.getContext('2d');
var startTime = Date.now();
setInterval( drawScene, 30);
<canvas id='cv' width=400 height=400></canvas>