Advertisement
here2share

# tk_500x500_rgb_cosmic_segment_zoom.py

Jan 22nd, 2024
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. # tk_500x500_rgb_cosmic_segment_zoom.py
  2.  
  3. import tkinter as tk
  4. import random
  5. from PIL import Image, ImageTk, ImageFilter, ImageDraw
  6.  
  7. ww = 500
  8. hh = 500
  9. cx = ww // 2
  10. cy = ww // 2
  11. p = 60
  12.  
  13. root = tk.Tk()
  14. root.title("# tk_500x500_rgb_cosmic_segment_zoom.py")
  15. root.geometry("%dx%d+%d+%d" %(ww, hh, 10, 10))
  16.  
  17. canvas = tk.Canvas(root, width=ww, height=hh)
  18. canvas.pack()
  19.  
  20. colors = []
  21. t = [z for z in range(0, 256, 15)]
  22. for r in t:
  23.     for g in t:
  24.         for b in t:
  25.             colors += [(r, g, b, 255)]
  26. Lc = len(colors)
  27.  
  28. def crop_center(img):
  29.     w, h = img.size
  30.     target_w, target_h = ww + 2, hh + 2
  31.     left = (w - target_w) // 2
  32.     top = (h - target_h) // 2
  33.     right = left + target_w
  34.     bottom = top + target_h
  35.     return img.crop((left, top, right, bottom))
  36.  
  37. alpha = 255 / 40
  38. black_image = Image.new('RGBA', (ww+p, hh+p), (0, 0, 0))
  39. def zoom():
  40.     global image_a, image_b
  41.     for i in range(1, 51):
  42.         image_a = crop_center(image_a)
  43.         image_a = image_a.resize((ww+p, hh+p), Image.BICUBIC)
  44.         img = image_a.filter(ImageFilter.GaussianBlur(1.0))
  45.         img = img.point(lambda x: x // 15 * 15)
  46.        
  47.         img = Image.blend(img.convert("RGBA"), black_image, max(0, i - 30) * 0.04)
  48.         img = img.convert("RGB")
  49.         plot(img)
  50.  
  51.     image_a, image_b = image_b, generate_new_image()
  52.  
  53. def generate_new_image():
  54.     global idx
  55.     size = 8
  56.     buffer = 0
  57.     for blur in (400, 400, 400, 400):
  58.         img = Image.new("RGBA", (size, size))
  59.         pixels = img.load()
  60.         for y in range(size):
  61.             for x in range(size):
  62.                 color = colors.pop(idx**3)
  63.                 idx = (idx + 1) % 16
  64.                 pixels[x, y] = color
  65.                 colors.append(color)
  66.         img = img.resize((ww+p, hh+p))
  67.         size *= 2
  68.     return img
  69.  
  70. def plot(buffer):
  71.     rgb_image = buffer.convert('RGB')
  72.     photo = ImageTk.PhotoImage(rgb_image)
  73.     canvas.create_image(cx, cy, anchor=tk.CENTER, image=photo)
  74.     canvas.image = photo
  75.     canvas.update()
  76.    
  77. t=50
  78. mask = Image.new('L', (ww+p, hh+p), 0)
  79. draw = ImageDraw.Draw(mask)
  80. for i in range(0, min(ww+p, hh+p) // 2, 10):
  81.     draw.rectangle([i, i, ww+p - i, hh+p - i], fill=i*255//((min(ww+p, hh+p) // 2)+1))
  82. mask_size = (ww+p, hh+p)
  83.  
  84. idx = 0
  85. image_a, image_b = [generate_new_image() for i in '..']
  86.  
  87. while True:
  88.     zoom()
  89.     idx += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement