Advertisement
here2share

# tk_intergalactic.py

May 19th, 2023 (edited)
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. # tk_intergalactic.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.05
  20.  
  21. cx, cy = ww//2, hh//2
  22. img = Image.new('RGB', (ww, hh), "white")
  23.  
  24. pixels = []
  25.  
  26. t = 100
  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. rnd = 50
  44. # Zoom effect
  45. while True:
  46.     for i in range(1000):
  47.         x, y = XY.pop(0)
  48.         XY.insert(-(10-(i%10)), (x, y))
  49.         r, g, b = img.getpixel((x,y))
  50.         r = max(0, min(255, r + random.randint(-rnd, rnd)))
  51.         g = max(0, min(255, g + random.randint(-rnd, rnd)))
  52.         b = max(0, min(255, b + random.randint(-rnd, rnd)))
  53.         img.putpixel((x, y), (r, g, b))
  54.  
  55.     xt, yt = int(ww+scale), int(hh+scale)
  56.     img = img.resize((xt, yt), resample=Image.LANCZOS)
  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