Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_solidgrays_at16_ani.py
- from tkinter import *
- from PIL import Image, ImageTk, ImageFilter, ImageDraw
- import copy
- ww = 256
- hh = 256
- cx, cy = ww//2, hh//2
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- rgb = range(0, 256, 10)
- 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.03 * min(img.size)
- def display(new_img):
- tkimg = ImageTk.PhotoImage(new_img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- root = Tk()
- root.title("tk_solidgrays_at16_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)
- sharpening_masks = []
- while 1:
- for y in xy:
- c = (c + 2) % 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 + 3) % 11
- draw['target'] = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- # Apply a lambda function to round the RGB values to the nearest multiple of 30
- draw['target'] = draw['target'].point(lambda p: round(p / 30) * 30)
- display(draw['target'])
- '''
- if draw['target'] not in sharpening_masks[:1]:
- sharpening_masks += [draw['target']]
- else:
- break
- print(len(sharpening_masks))
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement