Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_ImageFilter_GaussianBlur.py
- from tkinter import *
- from PIL import Image, ImageTk, ImageFilter
- from math import *
- root = Tk()
- ww = 500
- hh = 500
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- x, y = int(ww/2), int(hh/2)
- def cursor_pos(event):
- global x, y
- x = event.x
- y = event.y
- rnd = list([i*j for i in range(50,80) for j in (-1,1)])
- rnd.sort()
- o = [i for i in range(256)]
- o = o[1:-1]+o[::-1]
- L = len(o)
- def to_zero(n):
- """
- if n == 0:
- return 0
- """
- if int(n) > 0:
- return n-1
- return n+1
- rrr = ggg = bbb = 128
- yscan = [(128,128,128)] * ww
- img = Image.new("RGB",(ww,hh), "white")
- def draw():
- img.putdata(rgb)
- img2 = img.filter(ImageFilter.GaussianBlur(radius=7))
- imgTk = ImageTk.PhotoImage(img2)
- canvas.create_image(0, 0, anchor=NW, image=imgTk)
- canvas.update()
- ccc = 0
- while 1:
- rgb = []
- for i in range(hh):
- for j in range(ww):
- if not rrr:
- rrr = rnd.pop(ccc%2)
- rnd.append(rrr)
- ccc = ccc + 1
- if not ggg:
- ggg = rnd.pop(ccc%2)
- rnd.append(ggg)
- ccc = ccc + 1
- if not bbb:
- bbb = rnd.pop(ccc%2)
- rnd.append(bbb)
- ccc = ccc + 1
- r,g,b = yscan[j]
- rrr = to_zero(rrr)
- r2 = (r+rrr)
- ggg = to_zero(ggg)
- g2 = (g+ggg)
- bbb = to_zero(bbb)
- b2 = (b+bbb)
- ccc += 1
- t = (o[int(r2)%L], o[int(g2)%L], o[int(b2)%L])
- yscan[j] = t
- rgb += [t]
- draw()
Add Comment
Please, Sign In to add comment