Advertisement
here2share

# tk_phase_shift_infinite_zoom.py

May 30th, 2023
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # tk_phase_shift_infinite_zoom.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw, ImageFilter
  5. import math
  6. import random
  7.  
  8. ww = 600
  9. hh = 600
  10.  
  11. root = tk.Tk()
  12. root.title("tk_phase_shift_infinite_zoom")
  13. root.geometry("%dx%d+0+0"%(ww,hh))
  14. canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
  15. canvas.pack()
  16.  
  17. scale = 0
  18. zoom = 0.05
  19.  
  20. cx, cy = ww//2, hh//2
  21. img = Image.new('RGB', (ww, hh), "white")
  22.  
  23. pixels = []
  24.  
  25. t = 100
  26. cXY = [(x, y) for x in range(cx-t, cx+t) for y in range(cy-t, cy+t)]
  27. random.shuffle(cXY)
  28.  
  29. for y in range(hh):
  30.     for x in range(ww):
  31.         r, g, b = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
  32.         pixels.append((r, g, b))
  33.  
  34. img.putdata(pixels)
  35. tkimg = ImageTk.PhotoImage(img)
  36. canvas.create_image((cx, cy), image=tkimg)
  37. canvas.update()
  38.  
  39. o255 = {i: (i+47)%255 for i in range(256)}
  40. blur_radius = 0.0001 * min(img.size)
  41.  
  42. # Zoom effect
  43. while True:
  44.     if scale > 10:
  45.         for i in range(900):
  46.             x, y = cXY.pop(i*3)
  47.             cXY.append((x, y))
  48.             r, g, b = img.getpixel((x,y))
  49.             r = o255[r]
  50.             g = o255[g]
  51.             b = o255[(b-2)%255]
  52.             img.putpixel((x, y), (r, g, b))
  53.  
  54.     xt, yt = int(ww+scale), int(hh+scale)
  55.     img = img.resize((xt, yt), resample=Image.LANCZOS)
  56.     img = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
  57.    
  58.     # crop parameters to zoom into the center
  59.     img = img.crop((scale/2, scale/2, xt-scale/2, yt-scale/2))
  60.     scale += zoom
  61.    
  62.     tkimg = ImageTk.PhotoImage(img)
  63.     canvas.create_image((cx, cy), image=tkimg)
  64.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement