Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_inward_cache_demo.py
- import tkinter as tk
- WW, HH = 600, 600
- UNIT = 10
- root = tk.Tk()
- root.geometry('+0+0')
- canvas = tk.Canvas(root, width=WW, height=HH)
- canvas.pack()
- for y in range(0, HH, UNIT):
- for x in range(0, WW, UNIT):
- canvas.create_rectangle(x, y, x + UNIT, y + UNIT, outline='gray')
- cache = []
- def plot_unit(x, y):
- canvas.create_rectangle(x * UNIT, y * UNIT, (x + 1) * UNIT, (y + 1) * UNIT, fill='red', outline='')
- cache.append((x, y))
- root.update()
- def test():
- bb = (WW + 1) // UNIT
- i = 0
- j = bb
- while j:
- for x in range(i, j):
- plot_unit(x, j - 1)
- plot_unit(x, bb - j)
- i += 1
- j -= 1
- for y in range(i, j):
- plot_unit(j, y)
- plot_unit(bb - j - 1, y)
- test()
Advertisement
Add Comment
Please, Sign In to add comment