# Using Python to create a solar system
If anyone is looking for a fun exercise to flex their #Python #coding fingers…
Using just gravitational attraction between bodies, you can create your own 2D solar system with as many stars and planets as you want. Here's a binary star system with some relatively stable planets
Here's the article, including a detailed step-by-step tutorial, if you want to read more: **[Simulating Orbiting Planets in a Solar System Using Python](https://thepythoncodingbook.com/2021/09/29/simulating-orbiting-planets-in-a-solar-system-using-python-orbiting-planets-series-1/)**
#Python #simulation #animation
…and there's also a 3D version _(next post)_
@s_gruppetta That's very cool. Thanks for posting this!
@martinpeck both projects were fun to write (both the code itself and the articles!)
@s_gruppetta I hadn't really thought about using turtle for this sot of thing. It makes perfect sense now I see it!
@martinpeck `turtle` is a fun module to use, beyond the basic _draw a few squares_ type of tutorials you find.
I use it a lot for teaching and I try to push it to its limits and use it to teach more advanced topics, too
@s_gruppetta I haven't had a lot of usecases for 3D plotting with Matplotlib and usually stay in the 2D domain, but this a a beautiful showcase of its possibilities. Going to dive into the code, very cool 👍
@walterbogers Thank you. Hope you enjoy it. To be honest, most of the _real-world_ 3D plotting I've needed in the past was static. This is dynamic 3D plotting which, arguably, is less common (although of course it's useful for 4D data!)
@s_gruppetta This kind of dynamic 3D plotting is very useful for illustrating physics concepts like your example here, but in business applications it's indeed much less common and, in general, not necessary (at least in my company). But the fact that it's not used all over the place only enhances the coolness of this example 😉 I will certainly enjoy this!
@s_gruppetta this is really awesome! Given that it's for learning the coding side, I won't mark you down for using explicit integration 😜.
It's amazing how dynamic visualization can really solidify complex topics. Even when I've done iterative static computation in the past, dynamically-updating matplotlib plots really helped give me more intuition about the problem I was trying to solve.
@mattkram Yes, I find that I need to focus either on the coding aspect or on the science aspect, but you can't really do both–the article is already long as it is!
Agreed, in _real-world_ cases, the dynamic aspect adds an extra dimension which can help convey the results, in some cases, of course!
# 3D Solar System Using Matplotlib
The 3D version uses #matplotlib for the animation
Here's the article: **[Simulating a 3D Solar System In Python Using Matplotlib](https://thepythoncodingbook.com/2021/12/11/simulating-3d-solar-system-python-matplotlib/)**
#python #animation #simulation #planets #matplotlib