This five-part tutorial explains how you can create your own Solar System simulator or "orrery" using simple JavaScript. The end result will feature all the planets in their orbits around the sun based on a Gregorian input date.
Along the way you'll also learn a thing or two about Celestial Mechanics.
I've deliberately broken up this tutorial to keep things as understandable as possible. Each part contains workable code you can run locally on your machine.
Each code example is a pre-requisite for the next one, so I don't recommend skipping ahead. For example, in order to calculate planetary positions, you will first need to convert the commonly known Gregorian date into a Julian date.
In this JavaScript tutorial I don't waste any time on fluff. The completed JavaScript Solar System code is well under 500 lines.
I hope this tutorial helps you to create your own JS Solar System simulator. Have fun!
<HTML>
<HEAD>
<meta charset="UTF-8">
</HEAD>
<BODY>
<!-- CREATE CONTAINER TO HOLD BOTH CANVASES -->
<div id="CONTAINER" style="width:350px;height:350px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);">
<!-- BACKGROUND LAYER (Z-INDEX 0) -->
<canvas id="LAYER_BACKGROUND_T2" width="350" height="350" style="position: absolute; left: 0; top: 0; z-index: 0;">
</canvas>
<!-- FOREGROUND LAYER (Z-INDEX 1) -->
<canvas id="LAYER_FOREGROUND_T2" width="350" height="350" style="position: absolute; left: 0; top: 0; z-index: 1;">
</canvas>
</div>
<!-- JAVASCRIPT CODE -->
<script type="text/javascript" src="T2_createLayeredCanvas.js">
</script>
</BODY>
</HTML>