import math
import random


def create_spiral_galaxy(system_count=100, spirals=2):
    """
    Creates a spiral galaxy with given spirals (arms) and system count.
    The galaxy is unlinked and just creates the galaxy shape
    """
    sep = 2*math.pi/spirals

    spiral_list = []

    for x in range(spirals):
        spiral_list.append(x*sep)


    galaxy = {}

    for system in range(system_count):
        spiral_id = random.randint(0,spirals-1)
        length = random.random()
        dev_x = random.random()*random.choice([-1,1])*(1.0-length)*0.3
        dev_y = random.random()*random.choice([-1,1])*(1.0-length)*0.3
        dev_z = random.random()*random.choice([-1,1])*(1.0-length)*0.3
        spiral_flow = length*(math.pi*(36.0/180.0))+spiral_list[spiral_id]
        #spiral_flow = spiral_list[spiral_id]
        
        pos_x = math.cos(spiral_flow)*length+dev_x
        pos_y = math.sin(spiral_flow)*length+dev_y
        pos_z = dev_z

        galaxy[system] = {
            'position_x': pos_x,
            'position_y': pos_y,
            'position_z': pos_z,
            'id': system
        }

    return galaxy