Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_ultra_infinite_zoom.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import math
- import random
- ww = 600
- hh = 600
- root = tk.Tk()
- root.title("tk_ultra_infinite_zoom")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
- canvas.pack()
- cx, cy = ww//2, hh//2
- img = Image.new('RGB', (ww, hh), "white")
- pixels = []
- t = 100
- cXY = [(x, y) for x in range(cx-t, cx+t) for y in range(cy-t, cy+t)]
- random.shuffle(cXY)
- for y in range(hh):
- for x in range(ww):
- r, g, b = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
- pixels.append((r, g, b))
- img.putdata(pixels)
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- # calculate the blur radius to achieve 0.01% blur
- blur_radius = 0.0003 * min(img.size)
- scale = 15
- rnd = 50
- # Zoom effect
- while True:
- for i in range(1000):
- x, y = cXY.pop(0)
- cXY.insert(-(10-(i%10)), (x, y))
- r, g, b = img.getpixel((x,y))
- r = max(0, min(255, r + random.randint(-rnd, rnd)))
- g = max(0, min(255, g + random.randint(-rnd, rnd)))
- b = max(0, min(255, b + random.randint(-rnd, rnd)))
- img.putpixel((x, y), (r, g, b))
- img = img.resize((ww, hh), resample=Image.LANCZOS)
- img = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- # crop parameters to zoom into the center
- img = img.crop((scale/2, scale/2, ww-scale/2, hh-scale/2))
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement