Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_funky_rgb.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageFilter, ImageDraw
- ww = 600
- hh = 600
- cx, cy = ww // 2, hh // 2
- root = tk.Tk()
- root.title("tk_funky_rgb")
- root.geometry("%dx%d+%d+%d" % (ww, hh, 10, 10))
- canvas = tk.Canvas(root, width=ww, height=hh)
- canvas.pack()
- colors = []
- t = [z for z in range(0, 256, 9)]
- for r in t:
- for g in t:
- for b in t:
- colors += [(r, g, b, 255)]
- Lc = len(colors)
- def plot():
- photo = ImageTk.PhotoImage(buffer)
- canvas.create_image(cx, cy, anchor=tk.CENTER, image=photo)
- canvas.image = photo
- root.update()
- def crop_center(crop=15):
- return img.crop((crop, crop, ww-crop, hh-crop))
- p = 60
- def generate_new_image():
- global idx
- size = 8
- for blur in '.'*3:
- img = Image.new("RGB", (size, size))
- pixels = img.load()
- for y in range(size):
- for x in range(size):
- color = colors.pop(idx**3)
- idx = (idx + 1) % 16
- pixels[x, y] = color
- colors.append(color)
- img = img.resize((ww+p, hh+p))
- size *= 2
- img = img.resize((ww, hh))
- return img
- img = Image.new("RGB", (ww, hh), (128, 128, 128))
- idx = 0
- while 1:
- img = crop_center()
- img = img.resize((ww, hh), Image.BICUBIC)
- img = Image.blend(img, generate_new_image(), 0.05)
- buffer = img.filter(ImageFilter.GaussianBlur(5.0))
- buffer = buffer.point(lambda x: x // 25 * 40)
- plot()
- idx += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement