A simple star field.
This commit is contained in:
commit
0cdc3d2b0e
|
|
@ -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("<Configure>", 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',
|
||||
)
|
||||
Loading…
Reference in New Issue