import random

from datetime import datetime

print("AsteroidsRingMaker by JackDole in 2016.03.15 16:36:56 converted to Python and enhanced by FaceDeer, edit by quarior14")

print("daysYear = 365.24218985 days \n1 AU = 149597870.691 km\n1 Mass Earth = 5.9736e24 kg")

#uncomment this line if you want repeatable results

#random.seed(100)

# Amount of asteroids

NumberOfAster=input("Number of aster : ")

NumberOfAster = int(NumberOfAster)

TypeOfAster=input("Type of aster : ")

ClassOfAster=input("Class of aster : ")

RingCenter=input("Ring center : ")

print("Name of the asteroids - a serial number is appended")

AsterName=input("Aster name (no space between name and number) : ")

# Orbital radii in AU

InnerRadius=input("Inner Radius in AU : ")

InnerRadius = float(InnerRadius)

OuterRadius=input("Outer radius in AU : ")

OuterRadius = float(OuterRadius)

# Radius of asteroids in KM

MaxRadiusOfAster = input("Max radius in km : ")

MaxRadiusOfAster = float(MaxRadiusOfAster)

MinRadiusOfAster = input("Min radius in km : ")

MinRadiusOfAster = float(MinRadiusOfAster)

#orbital eccentricity

MaxEccentricity = input("Max eccentricity : ")

MaxEccentricity = float(MaxEccentricity)

MinEccentricity = input("Min eccentricity : ")

MinEccentricity = float(MinEccentricity)

# Orbital inclination +- in degrees

MaxInclination = input("Max inclination in degrees : ")

MaxInclination = float(MaxInclination)

#Probability that the asteroid won't be given a rotation rate, leaving it tide-locked

ChanceOfTideLock = input ("Chance of tidal lock (between 0 and 1) : ")

ChanceOfTideLock = float(ChanceOfTideLock)

#rotation periods in hours. See

https://www.boulder.swri.edu/~bottke/rubble/node3.html MaxRotationPeriod = input("Max rotation period in hours : ")

MaxRotationPeriod = float(MaxRotationPeriod)

MinRotationPeriod = input("Min rotation period in hours : ")

MinRotationPeriod = float(MinRotationPeriod)

RefPlane=input("RefPlane (Ecliptic, Equator, Extrasolar) : ")

epoch=input("Epoch : ")

FileName= '{0}_{1}.sc'.format(AsterName, NumberOfAster)

template ="""

{TypeOfAster} "{AsterName}{count}"

{{

\tParentBody\t"{RingCenter}"

\tClass\t\t"{ClassOfAster}"

\tRadius\t\t{radius}\t//in km

{rotation}

\tOrbit

\t{{

\t\tEpoch\t\t\t{epoch}

\t\tSemiMajorAxis\t{semi}\t//in AU

\t\tEccentricity\t{eccen}

\t\tInclination\t\t{incl}\t//in degrees

\t\tAscendingNode\t{ascen}

\t\tArgOfPericen\t{argof}

\t\tMeanAnomaly\t\t0.0

\t\tRefPlane\t\t"{RefPlane}"

\t}}

}}

"""

#three different random number generators that give a floating point number between

#the two parameters but with different distributions

def uniform(a, b):

return random.uniform(a, b)

def triangular(a, b):

return random.triangular(a, b, (a+b)/2.0)

# A normal distribution placing a and b at three standard deviations out from the mean

# clamping the result so that there are no outliers beyond the desired range

def gaussian(a, b):

result = random.gauss((a+b)/2.0, (b-a)/6.0)

return max(min(result, b), a)

randomGenerator = gaussian

parameters = {'TypeOfAster' : TypeOfAster, 'AsterName' : AsterName, 'RingCenter' : RingCenter, 'ClassOfAster' : ClassOfAster, 'RefPlane' : RefPlane, 'epoch' : epoch}

with open(FileName, 'w') as outputfile:

outputfile.write('// Asteroids made with AsteroidsRingMaker\n// {0}\n\n'.format(datetime.today()))

for count in range(NumberOfAster):

parameters['count'] = count+1

parameters['semi'] = randomGenerator(InnerRadius, OuterRadius)

parameters['radius'] = randomGenerator(MinRadiusOfAster, MaxRadiusOfAster)

parameters['incl'] = randomGenerator(-MaxInclination, MaxInclination)

parameters['eccen'] = randomGenerator(MinEccentricity, MaxEccentricity)

parameters['argof'] = random.uniform(0,360)

parameters['ascen'] = random.uniform(0,360)

if random.random() > ChanceOfTideLock:

rotation = randomGenerator(MinRotationPeriod,MaxRotationPeriod)

obliquity = random.uniform(0,360)

parameters['rotation'] = '\tRotationPeriod\t{0}\t//in hours\n\tObliquity\t\t{1}\n'.format(rotation, obliquity)

else:

parameters['rotation'] = '\t//RotationPeriod\tTidal locked'

outputfile.write(template.format(**parameters))

print("The script is save in the file "+FileName+".")

os.system ("pause")