Advertisement
here2share

# tk_funky_rgb.py

Feb 1st, 2024 (edited)
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. # tk_funky_rgb.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageFilter, ImageDraw
  5.  
  6. ww = 600
  7. hh = 600
  8. cx, cy = ww // 2, hh // 2
  9.  
  10. root = tk.Tk()
  11. root.title("tk_funky_rgb")
  12. root.geometry("%dx%d+%d+%d" % (ww, hh, 10, 10))
  13. canvas = tk.Canvas(root, width=ww, height=hh)
  14. canvas.pack()
  15.  
  16. colors = []
  17. t = [z for z in range(0, 256, 9)]
  18. for r in t:
  19.     for g in t:
  20.         for b in t:
  21.             colors += [(r, g, b, 255)]
  22. Lc = len(colors)
  23.  
  24. def plot():
  25.     photo = ImageTk.PhotoImage(buffer)
  26.     canvas.create_image(cx, cy, anchor=tk.CENTER, image=photo)
  27.     canvas.image = photo
  28.     root.update()
  29.  
  30. def crop_center(crop=15):
  31.     return img.crop((crop, crop, ww-crop, hh-crop))
  32.  
  33. p = 60
  34. def generate_new_image():
  35.     global idx
  36.     size = 8
  37.     for blur in '.'*3:
  38.         img = Image.new("RGB", (size, size))
  39.         pixels = img.load()
  40.         for y in range(size):
  41.             for x in range(size):
  42.                 color = colors.pop(idx**3)
  43.                 idx = (idx + 1) % 16
  44.                 pixels[x, y] = color
  45.                 colors.append(color)
  46.         img = img.resize((ww+p, hh+p))
  47.         size *= 2
  48.     img = img.resize((ww, hh))
  49.     return img
  50.  
  51. img = Image.new("RGB", (ww, hh), (128, 128, 128))
  52. idx = 0
  53. while 1:
  54.     img = crop_center()
  55.     img = img.resize((ww, hh), Image.BICUBIC)
  56.     img = Image.blend(img, generate_new_image(), 0.05)
  57.     buffer = img.filter(ImageFilter.GaussianBlur(5.0))
  58.     buffer = buffer.point(lambda x: x // 25 * 40)
  59.     plot()
  60.     idx += 1
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement