Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_native_contour.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("native_contour")
- 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]
- rgb = []
- def create_rgb():
- t = list(range(0, 256, 50))
- rrr = t[:]
- ggg = t[:]
- bbb = t[:]
- r = g = b = 0
- while 1:
- for r in rrr:
- for g in ggg:
- for b in bbb:
- if (r,g,b) not in rgb:
- rgb.append((r,g,b))
- else:
- return
- if bbb.index(b) == len(bbb) - 1:
- bbb = bbb[::-1]
- if ggg.index(g) == len(ggg) - 1:
- ggg = ggg[::-1]
- rrr = rrr[::-1]
- create_rgb()
- Lc = len(rgb)
- def contour():
- pixels = img2.load()
- for y in range(hh):
- for x in range(ww):
- r,g,b = pixels[x,y]
- r,g,b = rgb[(r+g+b)%Lc]
- 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))
- contour()
- tkimg = ImageTk.PhotoImage(img2)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- root.mainloop()
Add Comment
Please, Sign In to add comment