Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_phase_shift_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_phase_shift_infinite_zoom")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
- canvas.pack()
- scale = 0
- zoom = 0.05
- 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()
- o255 = {i: (i+47)%255 for i in range(256)}
- blur_radius = 0.0001 * min(img.size)
- # Zoom effect
- while True:
- if scale > 10:
- for i in range(900):
- x, y = cXY.pop(i*3)
- cXY.append((x, y))
- r, g, b = img.getpixel((x,y))
- r = o255[r]
- g = o255[g]
- b = o255[(b-2)%255]
- img.putpixel((x, y), (r, g, b))
- xt, yt = int(ww+scale), int(hh+scale)
- img = img.resize((xt, yt), 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, xt-scale/2, yt-scale/2))
- scale += zoom
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement