Here is an n-body gravitational simulation built in python. You can see the full python code here: https://trinket.io/glowscript/224b7a1b14bf
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.