Generate planets.

This commit is contained in:
Simon Forman 2024-04-13 17:39:02 -07:00
parent ddd68e2cb6
commit f40d466df1
2 changed files with 31 additions and 1 deletions

Binary file not shown.

View File

@ -28,11 +28,14 @@ Stars have what qualities?
- brightness - brightness
- size - size
- Game stats - Game stats
- age?
- ? - ?
🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘
''' '''
from random import randint, expovariate, seed, getrandbits from random import randint, expovariate, seed, getrandbits, gauss
from poisson import poisson from poisson import poisson
@ -69,6 +72,15 @@ def generate_list_of_u64_for_ids(n):
TABLES = [ TABLES = [
'create table stars (id INTEGER PRIMARY KEY, x INTEGER, y INTEGER, radius INTEGER)', 'create table stars (id INTEGER PRIMARY KEY, x INTEGER, y INTEGER, radius INTEGER)',
('''\
create table planets (
id INTEGER PRIMARY KEY,
ordo INTEGER,''' # The order from the star, counting from 1.
# I use "ordo" instead of "order" because "order" is a keyword
# in SQL (or at least it caused a syntax error in SQLite.)
'''star INTEGER,
FOREIGN KEY(star) REFERENCES stars(id)
)'''),
] ]
@ -77,6 +89,8 @@ def init_db(conn):
c = conn.cursor() c = conn.cursor()
for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS): for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS):
c.execute('insert into stars values (?, ?, ?, ?)', values) c.execute('insert into stars values (?, ?, ?, ?)', values)
star_id = values[0]
generate_planets_for_star(c, star_id)
c.close() c.close()
conn.commit() conn.commit()
@ -106,4 +120,20 @@ def how_many_planets():
n = round(gauss(5, 5)) n = round(gauss(5, 5))
return n return n
def generate_planets_for_star(c, star_id):
n = how_many_planets()
if n < 1:
return
for ordo in range(1, n + 1):
c.execute('insert into planets(ordo, star) values (?, ?)', (ordo, star_id))
ROMAN_NUMBERS = [
None,
'I', 'II', 'III', 'IV', 'V',
'VI', 'VII', 'VIII', 'IX', 'X',
'XI', 'XII', 'XIII', 'XIV', 'XV',
'XVI', 'XVII', 'XVIII', 'XIX', 'XX',
'XXI', 'XXII', 'XXIII', 'XXIV', 'XXV',
'XXVI', 'XXVII', 'XXVIII', 'XXIX',
]