here2share

# tk_entropy_spiral_infinite_zoom.py

Jun 7th, 2023
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. # tk_entropy_spiral_infinite_zoom.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw, ImageFilter
  5. import math
  6.  
  7. ww = 640
  8. hh = 640
  9.  
  10. root = tk.Tk()
  11. root.title("tk_entropy_spiral_infinite_zoom")
  12. root.geometry("%dx%d+0+0"%(ww,hh))
  13. canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
  14. canvas.pack()
  15.  
  16. cx, cy = ww//2, hh//2
  17. img = Image.new('RGB', (ww, hh), "white")
  18.  
  19. rgb = []
  20. def z(r,g,b):
  21.     rgb.append((r,g,b))
  22. r,g,b=255,0,0
  23. for g in range(256):
  24.     z(r,g,b)
  25. for r in range(254, -1, -1):
  26.     z(r,g,b)
  27. for b in range(256):
  28.     z(r,g,b)
  29. for g in range(254, -1, -1):
  30.     z(r,g,b)
  31. for r in range(256):
  32.     z(r,g,b)
  33. for b in range(254, -1, -1):
  34.     z(r,g,b)
  35. rgb*=30
  36. L = len(rgb)
  37.  
  38. cXY = []
  39. t = ww//4
  40. for y in range(t,t*3):
  41.     for x in range(t,t*3):
  42.         distance = ((cx-x)**2+(cy-y)**2)**0.5
  43.         if distance < ww//4:
  44.             xy2 = math.atan2(x-cx,y-cy)
  45.             cXY.append(((int(distance), xy2),x,y))
  46. cXY.sort()
  47. cXY = [(x,y) for z,x,y in cXY]
  48. LXY = len(cXY)
  49.  
  50. blur_radius = 0.0005 * min(img.size)
  51. scale = 30
  52. zoom = 0.01
  53.  
  54. def draw():
  55.     x, y = cXY[i]
  56.     r, g, b = rgb.pop(i%21)
  57.     rgb.append((r, g, b))
  58.     rrr, ggg, bbb = img.getpixel((x,y))
  59.     r = rrr + max(-clamp, min(clamp, r - rrr))
  60.     g = ggg + max(-clamp, min(clamp, g - ggg))
  61.     b = bbb + max(-clamp, min(clamp, b - bbb))
  62.     img.putpixel((x, y+1), (r, g, b))
  63.  
  64.  
  65. clamp = 80
  66. while True:
  67.     for i in range(0, LXY, 11):
  68.         draw()
  69.     cXY.append(cXY.pop(int(scale)%L))
  70.  
  71.     img = img.resize((ww, hh)) # , resample=Image.LANCZOS)
  72.     img = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
  73.    
  74.     # crop parameters to zoom into the center
  75.     img = img.crop((scale/2, scale/2, ww+1-scale/2, ww+1-scale/2))
  76.    
  77.     tkimg = ImageTk.PhotoImage(img)
  78.     canvas.create_image((cx, cy), image=tkimg)
  79.     canvas.update()
Add Comment
Please, Sign In to add comment