Advertisement
here2share

# tk_hyper_infinite_zoom.py

May 27th, 2023
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. # tk_hyper_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_hyper_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. # calculate the blur radius to achieve 0.01% blur
  40. blur_radius = 0.0003 * min(img.size)
  41.  
  42. rnd = 50
  43. # Zoom effect
  44. while True:
  45.     for i in range(1000):
  46.         x, y = cXY.pop(0)
  47.         cXY.insert(-(10-(i%10)), (x, y))
  48.         r, g, b = img.getpixel((x,y))
  49.         r = max(0, min(255, r + random.randint(-rnd, rnd)))
  50.         g = max(0, min(255, g + random.randint(-rnd, rnd)))
  51.         b = max(0, min(255, b + random.randint(-rnd, rnd)))
  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