Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_rgb_fuzzy.py
- from tkinter import *
- from PIL import Image, ImageTk
- import itertools
- from random import randint as ri, shuffle as rs
- import math
- ww = 512
- hh = 512
- root = Tk()
- root.title("tk_rgb_fuzzy")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- img = Image.new("RGB",(ww,hh), "white")
- R = [''.join(comb) for comb in itertools.product('abcdefghij', repeat=3)]
- G = [''.join(comb) for comb in itertools.product('klmnopqrst', repeat=3)]
- B = [''.join(comb) for comb in itertools.product('tuvwxyzABC', repeat=3)]
- RRR = []
- GGG = []
- BBB = []
- for i in range(len(R)):
- if len(set([R[i][0], R[i][1], R[i][2]])) == 3:
- RRR += [R[i]]
- GGG += [G[i]]
- BBB += [B[i]]
- x2 = 720.0/ww
- y2 = 720.0/hh
- buffer = []
- alpha = []
- for y in range(hh):
- b = int(y*y2)
- for x in range(ww):
- a = int(x*x2)
- c = (a+b) // 2
- ttt = f'{RRR[a]}{GGG[b]}{BBB[c]}'
- for i in range(len(ttt)-1):
- t = ttt[i:i+2]
- alpha.append(t)
- buffer += [ttt]
- alpha = sorted(list(set(alpha)))
- colors = []
- for r in range(0,256,5):
- for g in range(0,256,5):
- for b in range(0,256,5):
- colors += [(r,g,b)]
- i = 0
- while 1:
- rgb = []
- rs(colors)
- for z in buffer:
- i = ri(0,7)
- d = z[i]+z[i+1]
- idx = alpha.index(d)
- rgb += [colors[idx]]
- img.putdata(rgb)
- image_tk = ImageTk.PhotoImage(img)
- canvas.create_image(0,0,anchor=NW,image=image_tk)
- root.update()
Add Comment
Please, Sign In to add comment