Python: Random Star System Generator

No game reason for this really – I just like the idea of messing around in a quasi 3D star system using the Traveller vector movement.

The aim is to have a 3D box with all the stars, planets centered on a plane so you move in 2D but the visuals are 3D with all the orbiters having their own size, radius and orbit time so they move around on their orbits over time.

The code part is pretty easy if you simplify the orbits to circles. All you need is a class that has planet size, distance (from star) and orbit length. The orbit length gives you the number of degrees the planet moves per day so all you need is a method that takes a time, adds on the degrees moved and moves the planet’s center point.

class orbiter:
def __init__(self, tup): = tup[0]
self.radius = tup[1]
self.distance = tup[2]
self.days = tup[3]
self.dpd = 360/self.days
self.angle = random.randint(1,360)
self.x = 0
self.y = 0

def dodays(self,numdays):
numdegrees = self.dpd * numdays
self.angle = (self.angle+numdegrees) % 360

def dodraw(self):
radangle = math.radians(self.angle)
self.x = self.distance * math.sin(radangle)
self.y = self.distance * math.cos(radangle)

which currently ends up as this


(unrealistic orbit distances to test)(the button adds ten days)

This seems like it should actually be pretty easy but will wait until I’ve found out about Python’s Pygame module.


Got side tracked from this by the urge to do some Travellerized Dark Heresy chargen so that’s next.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: