here2share

# tk_dbl_zip_ani.py

Jul 12th, 2026
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. # tk_dbl_zip_ani.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw, ImageFont, ImageFilter, ImageEnhance
  5. import math
  6. from itertools import chain
  7.  
  8. WW, HH = 640, 640
  9. sz = 29
  10.  
  11. root = tk.Tk()
  12. root.geometry('+0+0')
  13. canvas = tk.Canvas(root, width=WW, height=HH)
  14. canvas.pack()
  15.  
  16. base = {
  17.     (0, 0): (255, 255, 255),   (0, 1): (255, 255,   0),   (0, 2): (0, 255,   0),
  18.     (1, 0): (255, 128,   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), base[(x, y)])
  25.  
  26. small_img = small_img.resize((sz, sz), Image.LANCZOS)
  27.  
  28. new_data = [small_img.getpixel((x, y)) for x in range(sz) for y in range(sz)]
  29.  
  30. def get_next_zip(p):
  31.     p = list(p)
  32.     mid = len(p) // 2
  33.     p = list(chain.from_iterable(zip(p[:mid], p[mid:])))
  34.     p.insert(0, p.pop(-1))
  35.     return tuple(chain.from_iterable(zip(p[mid:], p[:mid])))
  36.  
  37. while 1:
  38.     img = small_img.resize((WW, HH), Image.LANCZOS)
  39.     img = img.filter(ImageFilter.GaussianBlur(10))
  40.     photo = ImageTk.PhotoImage(img)
  41.     canvas.create_image(0, 0, anchor=tk.NW, image=photo)
  42.     root.update()
  43.  
  44.     new_data = get_next_zip(new_data)
  45.     small_img.putdata(new_data)
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment