here2share

# tk_ImageFilter_GaussianBlur.py

Dec 9th, 2022
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # tk_ImageFilter_GaussianBlur.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk, ImageFilter
  5. from math import *
  6.  
  7. root = Tk()
  8.  
  9. ww = 500
  10. hh = 500
  11.  
  12. canvas = Canvas(root, width=ww, height=hh)
  13. canvas.pack()
  14.  
  15. x, y = int(ww/2), int(hh/2)
  16.  
  17. def cursor_pos(event):
  18.     global x, y
  19.     x = event.x
  20.     y = event.y
  21.  
  22. rnd = list([i*j for i in range(50,80) for j in (-1,1)])
  23. rnd.sort()
  24.  
  25. o = [i for i in range(256)]
  26. o = o[1:-1]+o[::-1]
  27. L = len(o)
  28.  
  29. def to_zero(n):
  30.     """
  31.     if n == 0:
  32.         return 0
  33.     """
  34.     if int(n) > 0:
  35.         return n-1
  36.     return n+1
  37.    
  38. rrr = ggg = bbb = 128
  39.  
  40. yscan = [(128,128,128)] * ww
  41.  
  42. img = Image.new("RGB",(ww,hh), "white")
  43.  
  44. def draw():
  45.     img.putdata(rgb)
  46.     img2 = img.filter(ImageFilter.GaussianBlur(radius=7))
  47.     imgTk = ImageTk.PhotoImage(img2)
  48.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  49.     canvas.update()
  50.  
  51. ccc = 0
  52. while 1:
  53.     rgb = []
  54.     for i in range(hh):
  55.         for j in range(ww):
  56.                            
  57.             if not rrr:
  58.                 rrr = rnd.pop(ccc%2)
  59.                 rnd.append(rrr)
  60.                 ccc = ccc + 1
  61.             if not ggg:
  62.                 ggg = rnd.pop(ccc%2)
  63.                 rnd.append(ggg)
  64.                 ccc = ccc + 1
  65.             if not bbb:
  66.                 bbb = rnd.pop(ccc%2)
  67.                 rnd.append(bbb)
  68.                 ccc = ccc + 1
  69.  
  70.             r,g,b = yscan[j]
  71.            
  72.             rrr = to_zero(rrr)
  73.             r2 = (r+rrr)
  74.             ggg = to_zero(ggg)
  75.             g2 = (g+ggg)
  76.             bbb = to_zero(bbb)
  77.             b2 = (b+bbb)
  78.                
  79.             ccc += 1
  80.            
  81.             t = (o[int(r2)%L], o[int(g2)%L], o[int(b2)%L])
  82.             yscan[j] = t
  83.             rgb += [t]
  84.            
  85.     draw()
  86.  
Add Comment
Please, Sign In to add comment