Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_500x500_rgb_gel_ani.py
- import tkinter as tk
- import random
- from PIL import Image, ImageTk, ImageFilter
- ww = 500
- hh = 500
- cx = ww // 2
- cy = ww // 2
- root = tk.Tk()
- root.title("tk_500x500_rgb_gel_ani")
- 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, 15)]
- for r in t:
- for g in t:
- for b in t:
- colors += [(r, g, b, 255)]
- Lc = len(colors)
- def generate(event=None):
- for size in layers:
- interpolate(size)
- draw()
- def interpolate(size):
- global idx
- img = Image.new("RGBA", (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+20, hh+20))
- layers[size] = img
- def draw(event=None):
- buffer = Image.new("RGBA", (ww+20, hh+20), (255, 255, 255, 255))
- for size, layer_image in layers.items():
- buffer = Image.blend(buffer, layer_image, 400 / 1000.0)
- buffer = buffer.point(lambda x: x // 25 * 25)
- photo = ImageTk.PhotoImage(buffer)
- canvas.create_image(cx, cy, anchor=tk.CENTER, image=photo)
- canvas.image = photo
- canvas.update()
- layers = {}
- idx = 0
- size = 8
- for i in (512, 512):
- interpolate(size)
- size *= 2
- while True:
- generate()
- idx += 1
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement