Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_rgb_blur_blend_at16_ani.py
- from tkinter import *
- from PIL import Image, ImageTk, ImageFilter, ImageDraw
- from math import sin, cos, pi
- import copy
- ww = 512
- hh = 512
- cx, cy = ww//2, hh//2
- root = Tk()
- root.title("tk_rgb_blur_blend_at16_ani")
- root.geometry("%dx%d+0+0"%(ww,hh))
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- rgb = range(0, 256, 50)
- colors = [rgb2hex(r, g, b) for r in rgb for g in rgb for b in rgb]
- img = Image.new('RGB', (ww, hh), (0, 0, 0))
- draw = {}
- for k in (0, 1, 2, 3):
- draw[k] = ImageDraw.Draw(img)
- blur_radius = 0.02 * min(img.size)
- canvas = Canvas(root, width=ww, height=hh, bg='white')
- canvas.pack(side=LEFT, fill=BOTH, expand=True)
- def display():
- tkimg = ImageTk.PhotoImage(draw['image'])
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- sz = 16
- c = 0
- xy = range(0, 512, sz)
- for y in xy:
- c = (c + 3) % 11
- for x in xy:
- color = colors.pop(c)
- colors.append(color)
- draw[1].rectangle((x, y, x+sz, y+sz), fill=color, outline=color)
- c = (c + 1) % 11
- draw['source'] = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- source = {}
- target = {}
- for y in range(hh):
- for x in range(ww):
- source[x,y] = draw['source'].getpixel((x, y))
- o255 = [i for i in range(256)]
- o255 = o255[1:-1] + o255[::-1]
- Lc = len(o255)
- def waves():
- for i in range(0, 100):
- alpha = i / 100.0
- draw['image'] = Image.blend(draw['source'], draw['target'], alpha)
- display()
- draw['source'] = copy.deepcopy(draw['target'])
- while 1:
- for y in xy:
- c = (c + 1) % 11
- for x in xy:
- color = colors.pop(c)
- colors.append(color)
- draw[0].rectangle((x, y, x+sz, y+sz), fill=color, outline=color)
- c = (c + 1) % 11
- draw['target'] = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- waves()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement