Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_seq_infinite_zoom.py
- # without random
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import math
- ww = 640
- hh = 640
- root = tk.Tk()
- root.title("tk_seq_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.25
- cx, cy = ww//2, hh//2
- img = Image.new('RGB', (ww, hh), "white")
- rgb = []
- def create_rgb():
- t = list(range(0, 256, 50))
- rrr = t[:]
- ggg = t[:]
- bbb = t[:]
- r = g = b = 0
- while 1:
- for r in rrr:
- for g in ggg:
- for b in bbb:
- if (r,g,b) not in rgb:
- rgb.append((r,g,b))
- else:
- return
- if bbb.index(b) == len(bbb) - 1:
- bbb = bbb[::-1]
- if ggg.index(g) == len(ggg) - 1:
- ggg = ggg[::-1]
- rrr = rrr[::-1]
- create_rgb()
- L = len(rgb)
- pixels = []
- t = 90
- cXY = []
- for y in range(cy-t, cy+t):
- for x in range(cx-t, cx+t):
- distance = ((cx-x)**2+(cy-y)**2)**0.5
- if distance < t+1:
- xy2 = math.atan2(x-cx,y-cy)
- cXY.append(((int(distance), xy2),x,y))
- cXY.sort()
- cXY = [(x,y) for z,x,y in cXY]
- for i, (x, y) in enumerate(cXY):
- img.putpixel((x, y), rgb[i%L])
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- # Zoom effect
- clamp = 5
- while True:
- if scale > 20:
- for i in range(0, len(cXY), 5):
- x, y = cXY[i]
- r, g, b = rgb.pop(0)
- rgb.insert(-(10-(i%10)), (r, g, b))
- rrr, ggg, bbb = img.getpixel((x,y))
- r = rrr + max(-clamp, min(clamp, r - rrr))
- g = ggg + max(-clamp, min(clamp, g - ggg))
- b = bbb + max(-clamp, min(clamp, b - bbb))
- img.putpixel((x, y), (r, g, b))
- t = cXY.pop(0)
- cXY.append(t)
- xt, yt = int(ww+scale), int(hh+scale)
- img = img.resize((xt, yt), resample=Image.LANCZOS)
- # 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()
Add Comment
Please, Sign In to add comment