Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_layered_contours.py
- from tkinter import *
- from PIL import Image, ImageTk, ImageFilter, ImageDraw
- import math
- ww = 512
- hh = 512
- cx, cy = ww//2, hh//2
- root = Tk()
- root.title("layered_contours")
- root.geometry("%dx%d+0+0"%(ww,hh))
- img = Image.new('RGB', (ww, hh), (0, 0, 0))
- draw = ImageDraw.Draw(img)
- blur_radius = 0.06 * min(img.size)
- canvas = Canvas(root, width=ww, height=hh, bg='white')
- canvas.pack(side=LEFT, fill=BOTH, expand=True)
- 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]
- Lc = len(colors)
- def layered_contours():
- intensity = 20
- pixels = img2.load()
- for y in range(hh):
- for x in range(ww):
- r,g,b = pixels[x,y]
- r,g,b = [i//intensity*intensity for i in (r,g,b)]
- pixels[x,y] = (r,g,b)
- sz = 64
- i = 0
- xy = range(0, 512, sz)
- while 1:
- for y in xy:
- i = (i + 1) % 11
- for x in xy:
- color = colors.pop(i)
- colors.append(color)
- draw.rectangle((x, y, x+sz, y+sz), fill=color, outline=color)
- i = (i + 1) % 11
- img2 = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- layered_contours()
- tkimg = ImageTk.PhotoImage(img2)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement