Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_dbl_zip_ani.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFont, ImageFilter, ImageEnhance
- import math
- from itertools import chain
- WW, HH = 640, 640
- sz = 29
- root = tk.Tk()
- root.geometry('+0+0')
- canvas = tk.Canvas(root, width=WW, height=HH)
- canvas.pack()
- base = {
- (0, 0): (255, 255, 255), (0, 1): (255, 255, 0), (0, 2): (0, 255, 0),
- (1, 0): (255, 128, 0), (1, 1): (128, 128, 128), (1, 2): (0, 0, 255),
- (2, 0): (255, 0, 0), (2, 1): (128, 0, 128), (2, 2): (0, 0, 0)
- }
- small_img = Image.new('RGB', (3, 3))
- for y in range(3):
- for x in range(3):
- small_img.putpixel((x, y), base[(x, y)])
- small_img = small_img.resize((sz, sz), Image.LANCZOS)
- new_data = [small_img.getpixel((x, y)) for x in range(sz) for y in range(sz)]
- def get_next_zip(p):
- p = list(p)
- mid = len(p) // 2
- p = list(chain.from_iterable(zip(p[:mid], p[mid:])))
- p.insert(0, p.pop(-1))
- return tuple(chain.from_iterable(zip(p[mid:], p[:mid])))
- while 1:
- img = small_img.resize((WW, HH), Image.LANCZOS)
- img = img.filter(ImageFilter.GaussianBlur(10))
- photo = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=tk.NW, image=photo)
- root.update()
- new_data = get_next_zip(new_data)
- small_img.putdata(new_data)
Advertisement
Add Comment
Please, Sign In to add comment