Python coding a planetary ring field system

Project Page Next project post Post History

Happy Easter everyone!

This weekend is a long one with the Easter break upon us. Here in Adelaide the weather has been a bit rainy. And since it's a long weekend, I decided to try my hand at something a little new.

In the passed week, one of the trainers at my course showed us an example of putting some random objects in a scene using Python. So, I decided to try a new coding language, and took the idea home to see if I could make a simple planetary system with a ring debris field around it. I downloaded a student version of Maya and started playing around. Here's what I came up with:

The concept was pretty simple. I added a sphere (our planet!) and gave it some tilt, much like our own Earth. I built upon this by adding a ring field around it, with randomly scattered piees of debris to create a ring field around the planet. The debris is just made of smaller polygon-light spheres. Upon looking at the results, I found the distribution of the debris a bit linear-looking (see progression images at the end of this post). I decided to try fix this by adding some sort of weighted distribution to the debris. All I was attempting to do was pull things in towards the centre of the ring a little more, just to try break up those harsh-looking edges on the outer edges of the ring. When this started working better, I went the final step and gave the code the ability to make more than one ring field.

Imagine having to place all those objects individually into the scene? There's 20,000 pieces combined in those two ring fields. You can see how helpful it can be to do something like this programmatically. All this was done in less than two-hundred lines of code. And without the comments, probably under one-fifty.

As a final touch, I added some rotation animation via script to the planet as well, so the whole system rotates around the planet axis. Video loop below.

Here are some rendered images showing the progression through the various stages of building the planet system:

One of the first renders with the planet and a simple ring field
First attempt to add some sort of weighted distribution to the ring field objects
A more successful weighted distribution of the ring field
Some randomness added to the debris size
The final planetary system with two ring fields.