-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquares.py
More file actions
34 lines (23 loc) · 776 Bytes
/
squares.py
File metadata and controls
34 lines (23 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import tkinter
SQUARES = int(input("depth: "))
MASTER = tkinter.Tk()
MASTER.title("Squares")
CANVAS = tkinter.Canvas(MASTER, bg="white", width = 2 ** SQUARES, height = 2 ** SQUARES)
def color(h: int) -> str:
if h < 16:
return '#' + ('0' + hex(h)[2:]) * 3
return '#' + hex(h)[2:] * 3
def step(event: tkinter.Event) -> None:
CANVAS.delete("all")
ex = event.x - 2
ey = event.y - 2
for i in range(SQUARES, -1, -1):
x = 2 + ex - ex % 2 ** i
y = 2 + ey - ey % 2 ** i
CANVAS.create_rectangle(x, y, x + 2 ** i - 1, y + 2 ** i - 1, fill=color(i * 28))
def main() -> None:
MASTER.bind("<Motion>", step)
CANVAS.pack()
MASTER.mainloop()
if __name__ == "__main__":
main()