Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_autoblur.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageFilter
- WW, HH = 600, 600
- root = tk.Tk()
- canvas = tk.Canvas(root, width=WW, height=HH)
- root.geometry("%dx%d+10+10" % (WW, HH))
- canvas.pack()
- base = {
- (0, 0): (255, 255, 255), (0, 1): (255, 255, 0), (0, 2): (0, 255, 0),
- (1, 0): (255, 165, 0), (1, 1): (128, 128, 128), (1, 2): (0, 0, 255),
- (2, 0): (255, 0, 0), (2, 1): (128, 0, 128), (2, 2): (0, 0, 0)
- }
- def lerp(a, b, t):
- return a + (b - a) * t
- grid_colors = {}
- for i in range(7):
- for j in range(7):
- x = i * 2 / 6
- y = j * 2 / 6
- x0 = int(x)
- y0 = int(y)
- x1 = min(2, x0 + 1)
- y1 = min(2, y0 + 1)
- tx = x - x0
- ty = y - y0
- c00 = base[(x0, y0)]
- c10 = base[(x1, y0)]
- c01 = base[(x0, y1)]
- c11 = base[(x1, y1)]
- final = []
- for k in range(3):
- top = lerp(c00[k], c10[k], tx)
- bot = lerp(c01[k], c11[k], tx)
- val = lerp(top, bot, ty)
- final.append(int(val))
- grid_colors[(i, j)] = tuple(final)
- img = Image.new("RGB", (7, 7))
- for i in range(7):
- for j in range(7):
- img.putpixel((i, j), grid_colors[i, j])
- img = img.resize((WW, HH), Image.NEAREST)
- def update_gradient(val):
- radius = int(val)
- blurred = img.filter(ImageFilter.GaussianBlur(radius))
- photo = ImageTk.PhotoImage(blurred)
- canvas.image = photo
- canvas.create_image(0, 0, anchor="nw", image=photo)
- canvas.update()
- return blurred
- val = 0
- while 1:
- blurred = update_gradient(val)
- rgb = blurred.getpixel((0, 0))
- print(rgb)
- if rgb == (255, 255, 255):
- val += 1
- continue
- print(val)
- break
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment