Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_entropy_spiral_infinite_zoom.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import math
- ww = 640
- hh = 640
- root = tk.Tk()
- root.title("tk_entropy_spiral_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")
- rgb = []
- def z(r,g,b):
- rgb.append((r,g,b))
- r,g,b=255,0,0
- for g in range(256):
- z(r,g,b)
- for r in range(254, -1, -1):
- z(r,g,b)
- for b in range(256):
- z(r,g,b)
- for g in range(254, -1, -1):
- z(r,g,b)
- for r in range(256):
- z(r,g,b)
- for b in range(254, -1, -1):
- z(r,g,b)
- rgb*=30
- L = len(rgb)
- cXY = []
- t = ww//4
- for y in range(t,t*3):
- for x in range(t,t*3):
- distance = ((cx-x)**2+(cy-y)**2)**0.5
- if distance < ww//4:
- 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]
- LXY = len(cXY)
- blur_radius = 0.0005 * min(img.size)
- scale = 30
- zoom = 0.01
- def draw():
- x, y = cXY[i]
- r, g, b = rgb.pop(i%21)
- rgb.append((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+1), (r, g, b))
- clamp = 80
- while True:
- for i in range(0, LXY, 11):
- draw()
- cXY.append(cXY.pop(int(scale)%L))
- 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+1-scale/2, ww+1-scale/2))
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
Add Comment
Please, Sign In to add comment