Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_ultra_infinite_zoom_2.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_2")
- root.geometry("%dx%d+10+10"%(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.0001 * min(img.size)
- scale = 29
- rrr = 27
- ggg = 11
- bbb = 21
- # Zoom effect
- while True:
- for i in range(2500):
- x, y = cXY.pop(0)
- cXY.insert(-(i%10), (x, y))
- r, g, b = img.getpixel((x,y))
- if -1 < (r + rrr) < 256:
- r = (r + rrr)
- else:
- rrr *= -1
- if -1 < (g + ggg) < 256:
- g = (g + ggg)
- else:
- ggg *= -1
- if -1 < (b + bbb) < 256:
- b = (b + bbb)
- else:
- bbb *= -1
- xy0 = [(x+1, y), (x, y+1), (x-1, y), (x, y-1)][i%4]
- img.putpixel(xy0, (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()
Add Comment
Please, Sign In to add comment