here2share

# tk_freakshow_zoom.py

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