From 0cdc3d2b0ea2b6e173385e5c72857df8959d3058 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Thu, 11 Apr 2024 20:54:55 -0700 Subject: [PATCH] A simple star field. --- ui.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ui.py diff --git a/ui.py b/ui.py new file mode 100644 index 0000000..af13b39 --- /dev/null +++ b/ui.py @@ -0,0 +1,62 @@ +from fractions import Fraction as ratio +from tkinter import * +from PIL import Image +from PIL.ImageTk import PhotoImage + + + +class App: + ''' + A canvas with scrolling support. + ''' + + def __init__(self, master=None, *canvas_args, **canvas_kw): + frame = self.frame = Frame(root, bg='green') + frame.rowconfigure(0, weight=1) + frame.columnconfigure(0, weight=1) + + C = self.canvas = Canvas(frame, *canvas_args, **canvas_kw) + + scrollY = self.scrollY = Scrollbar( + frame, + orient=VERTICAL, + command=C.yview, + ) + C['yscrollcommand'] = scrollY.set + + scrollX = self.scrollX = Scrollbar( + frame, + orient=HORIZONTAL, + command=C.xview, + ) + C['xscrollcommand'] = scrollX.set + + C.grid(row=0, column=0, sticky=N+S+E+W) + scrollY.grid(row=0, column=1, sticky=N+S) + scrollX.grid(row=1, column=0, sticky=E+W) + + C.bind("", self.handle_canvas_resize) + + def handle_canvas_resize(self, event): + print(event) + + + + +from random import randint, expovariate + +width, height = 10240, 7680 +root = Tk() +app = App(root, bg='black', scrollregion=(0, 0, width, height)) +app.frame.pack(expand=True, fill=BOTH) + + +for _ in range(1000): + x, y = randint(0, width - 1), randint(0, height - 1) + #radius = randint(2, 10) // 2 + radius = round(1 + expovariate(1)) + app.canvas.create_oval( + x - radius, y - radius, + x + radius, y + radius, + fill='yellow', + )