Saturday, 20 December 2014

And here comes the whole Solar System! ;)

Modelling Sun, Earth and Moon only? Naah that’s too naive. Let’s add some other planets! Occhiolino
The code on my previous article was rather ugly. It did not follow an OOP style and it was mostly non re-usable. Aside from the content of the piece of code I posted in this article, I’m quite satisfied with how I set it: a class for planets and a class to handle time. Sure, perhaps this is not the smartest way of using a class, however for someone like me, who programs mainly as a hobby, that’s fine I guess.
This piece of code models and simulates the whole Solar System (without the Sun, you can add it though!) and gives you, aside from the code, a hint on how slow/fast planets are orbiting around the Sun. note that I use large intervals of time (10000 seconds or similar). This model for sure can be improved. For instance the colours could be improved and, jokes aside, perhaps elliptical orbits could be implemented instead of circular. To do that I still need to work on my knowledge of gravity and its implementation in Python.
solar sys

Anyway I’ll keep you posted. That’s it for now, here’s the code of the model and the YouTube video I made (but couldn’t load in the post, not sure why)

[EDIT]: I've finally made it and load the video here too! Enjoy


  1. Hi sir,
    how to install package 'visual' and 'bigfloat' on Windows10 and python 3?

    1. Hi Graziano, open a command prompt or a powershell prompt and type "pip install vpython" (without the quote marks). Then do the same with bigfloat. Bigfloat installation through pip might not work, if that is the case, you can download a .whl file of the package (to be installed by typing in the command prompt "pip install filename.whl") at this address:

  2. I got error in line 135 and 136.
    I could run this after modifying 'axis=(0,0,1)' to 'axis=vector(0,0,1)'.

    1. Additionally I used 'from vpython import *' instead of 'from visual import *'