Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_pseudo_turing_ani.py
- from tkinter import *
- from PIL import Image, ImageTk, ImageFilter, ImageDraw, ImageEnhance
- import copy
- ww = 600
- hh = 600
- cx, cy = ww//2, hh//2
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- def display(new_img):
- tkimg = ImageTk.PhotoImage(new_img)
- canvas.create_image(0, 0, anchor=NW, image=tkimg)
- canvas.update()
- root = Tk()
- root.title("tk_pseudo_turing_ani")
- root.geometry("%dx%d+10+10"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh, bg='white')
- canvas.pack(side=LEFT, fill=BOTH, expand=True)
- sz = 16
- span = ww//sz
- c = 0
- xy = range(0, sz*span, sz)
- rgb = range(0, 256, 25)
- colors = [rgb2hex(z, z, z) for z in rgb]
- img = Image.new('RGB', (ww, hh), (0, 0, 0))
- draw = {}
- draw[0] = ImageDraw.Draw(img)
- blur_radius = 0.025 * min(img.size)
- sz = 30
- c = 0
- xy = range(0, sz*20, sz)
- for y in xy:
- c = (c + 3) % 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['source'] = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- def apply_color_threshold(p):
- if p > 128:
- return 0
- else:
- return 255
- def waves():
- for i in range(0, 100):
- alpha = i / 100.0
- img2 = Image.blend(draw['source'], draw['target'], alpha)
- # Apply the color threshold using Image.point for each channel (R, G, B)
- r, g, b = img2.split()
- g = g.point(apply_color_threshold)
- img2 = Image.merge('RGB', (r, g, b)) # Merge the modified channels back into an RGB image
- display(img2)
- 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