Advertisement
here2share

# tk_pulsate_zoom.py

Jun 27th, 2025
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # tk_pulsate_zoom.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk
  5. import random
  6.  
  7. WW, HH = 640, 640
  8. scale = 20
  9. blend_alpha = 0.025  # Subtle blend effect
  10.  
  11. root = tk.Tk()
  12. root.title("# tk_pulsate_zoom.py")
  13. canvas = tk.Canvas(root, width=WW, height=HH)
  14. canvas.pack()
  15.  
  16. grid_colors = {
  17.     (0, 0): (255, 255, 255), (0, 1): (255, 255, 0), (0, 2): (0, 255, 0),
  18.     (1, 0): (255, 165, 0),   (1, 1): (128, 128, 128), (1, 2): (0, 0, 255),
  19.     (2, 0): (255, 0, 0),     (2, 1): (128, 0, 128),   (2, 2): (0, 0, 0)
  20. }
  21. small_img = Image.new('RGB', (3, 3))
  22. for y in range(3):
  23.     for x in range(3):
  24.         small_img.putpixel((x, y), grid_colors[(x, y)])
  25. base_img = small_img.resize((WW, HH), Image.LANCZOS)
  26. shuffle_img = small_img.resize((7, 7), Image.LANCZOS)
  27. data = list(shuffle_img.getdata())
  28.  
  29. def shuffled_image():
  30.     random.shuffle(data)
  31.     small_shuffled = Image.new('RGB', (7, 7))
  32.     small_shuffled.putdata(data)
  33.     return small_shuffled.resize((WW, HH), Image.LANCZOS)
  34.  
  35. img = base_img.copy()
  36. photo = ImageTk.PhotoImage(img)
  37. shuffled_img = Image.new('RGB', img.size)
  38. canvas.create_image(0, 0, image=photo, anchor=tk.NW)
  39.  
  40. i = 0
  41.  
  42. while True:
  43.     zoomed = img.resize((WW, HH))
  44.     photo = ImageTk.PhotoImage(zoomed)
  45.     canvas.create_image(0, 0, image=photo, anchor=tk.NW)
  46.  
  47.     img = img.crop((scale, scale, WW - scale, HH - scale))
  48.     img = img.resize((WW, HH))
  49.     i += 1
  50.     if i > 10:
  51.         shuffled_img = shuffled_image()
  52.         i = 0
  53.     img = Image.blend(img, shuffled_img, alpha=blend_alpha)
  54.  
  55.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement