diff --git a/data.py b/data.py index 64288a1..f9f32d3 100644 --- a/data.py +++ b/data.py @@ -39,6 +39,7 @@ def initialize_db_tables(filename): def close_db(): + global conn if conn: conn.close() conn = None @@ -54,11 +55,6 @@ def open_db(filename=FILENAME): return conn -def generate_stars(width, height, minimum_distance_between_stars): - for x, y in poisson(width, height, minimum_distance_between_stars): - yield x, y, round(1 + expovariate(1)) - - def main(filename): print('Initializing db file', filename) conn = initialize_db_tables(filename) diff --git a/stars.py b/stars.py index 5fee24e..f829098 100644 --- a/stars.py +++ b/stars.py @@ -18,10 +18,11 @@ # along with game. If not see . # from random import randint, expovariate, seed -import sqlite3 from poisson import poisson +seed(23) + MINIMUM_DISTANCE_BETWEEN_STARS = 160 WIDTH, HEIGHT = 10240, 7680 @@ -38,7 +39,6 @@ def generate_stars(width, height, minimum_distance_between_stars): def init_db(conn): print('Generating star data.') - seed(23) c = conn.cursor() for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS): c.execute('insert into stars values (?, ?, ?)', values) diff --git a/ui.py b/ui.py index 11b7723..d212b18 100755 --- a/ui.py +++ b/ui.py @@ -32,6 +32,7 @@ class App: frame = self.frame = Frame(root, bg='green') frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) + frame.pack(expand=True, fill=BOTH) C = self.canvas = Canvas(frame, *canvas_args, **canvas_kw) @@ -63,13 +64,18 @@ data.open_db() root = Tk() app = App(root, bg='black', scrollregion=(0, 0, stars.WIDTH, stars.HEIGHT)) -app.frame.pack(expand=True, fill=BOTH) for x, y, radius in stars.iter_stars(data.conn): - app.canvas.create_oval( + star_id = app.canvas.create_oval( x - radius, y - radius, x + radius, y + radius, fill='yellow', + outline='yellow', + activefill='#550', + activeoutline='orange', + activewidth=3, ) + app.canvas.tag_bind(star_id, '', (lambda event, sid=star_id, x=x, y=y: root.title(f'{x}, {y}'))) app.frame.mainloop() +data.close_db()