Advertisement
here2share

# tk_intergalactic_test.py

May 18th, 2023
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. # tk_intergalactic_test.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw, ImageFilter
  5. import math
  6. import random
  7. import io
  8.  
  9. ww = 599
  10. hh = 599
  11.  
  12. root = tk.Tk()
  13. root.title("tk_intergalactic")
  14. root.geometry("%dx%d+0+0"%(ww,hh))
  15. canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
  16. canvas.pack()
  17.  
  18. scale = 0
  19. zoom = 0.1
  20.  
  21. cx, cy = ww//2, hh//2
  22. img = Image.new('RGB', (ww, hh), "white")
  23.  
  24. pixels = []
  25.  
  26. t = 50
  27. XY = [(x, y) for x in range(cx-t, cx+t) for y in range(cy-t, cy+t)]
  28. random.shuffle(XY)
  29.  
  30. for y in range(hh):
  31.     for x in range(ww):
  32.         r, g, b = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
  33.         pixels.append((r, g, b))
  34.  
  35. img.putdata(pixels)
  36. tkimg = ImageTk.PhotoImage(img)
  37. canvas.create_image((cx, cy), image=tkimg)
  38. canvas.update()
  39.  
  40. # calculate the blur radius to achieve 0.01% blur
  41. blur_radius = 0.0009 * min(img.size)
  42.  
  43. # Zoom effect
  44. while True:
  45.     draw = ImageDraw.Draw(img)
  46.     color = "#{:02x}{:02x}{:02x}".format(*[random.randint(0, 255) for _ in range(3)])
  47.     draw.ellipse((cx - 1, cy - 1, cx + 1, cy + 1), fill=color) 
  48.     for i in range(5):
  49.         x, y = XY.pop(0)
  50.         XY.insert(-(5-i), (x, y))
  51.         color = "#{:02x}{:02x}{:02x}".format(*[random.randint(0, 255) for _ in range(3)])
  52.         draw.ellipse((x, y, x + 1, y + 1), fill=color)
  53.  
  54.     xt, yt = int(ww+scale), int(hh+scale)
  55.     img = img.resize((xt, yt), resample=Image.LANCZOS)
  56.    
  57.     img = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
  58.    
  59.     # crop parameters to zoom into the center
  60.     img = img.crop((scale/2, scale/2, xt-scale/2, yt-scale/2))
  61.     scale += zoom
  62.    
  63.     tkimg = ImageTk.PhotoImage(img)
  64.     canvas.create_image((cx, cy), image=tkimg)
  65.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement