Launched in November 2017.

Displays a full solar system with planets doing circular movement due to gravity pull of the sun

Written entirely on JavaScript

I used an interval that repeats an algorithm for about 30 miliseconds. The algorithm spawns the point-planets with the position (random(0, canvas.width / 2) , canvas.height / 2) and a starting point towards the bottom of the canvas.





Than I used the formulas of my book that calculate the gravitational force with which the planets are pulled towards the sun performing circular orbits. The formula i used for gravitational force is F = planetMass * sunMass * gama / distance^2.





To make the orbits circular I set this force equal to circular force F = Mass * Speed / distance;

Through that I could define the starting speed of each planet.





If you want to see some weird planet orbits try changing the parameters of the browser window on your desktop or by rotating the phone screen if you're on mobile. This weird movements will happen because the position of the sun will be changed as i set it to always be at the center of the screen.





I hope you like this project.





Update





Happy to inform this project was published in a JavaScript magazine.





Source: https://js.libhunt.com/newsletter/86