here2share

# tk_rgb_fuzzy.py

Apr 22nd, 2023
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # tk_rgb_fuzzy.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import itertools
  6. from random import randint as ri, shuffle as rs
  7. import math
  8.  
  9. ww = 512
  10. hh = 512
  11. root = Tk()
  12. root.title("tk_rgb_fuzzy")
  13. root.geometry("%dx%d+0+0"%(ww,hh))
  14. canvas = Canvas(root, width=ww, height=hh)
  15. canvas.grid()
  16.  
  17. img = Image.new("RGB",(ww,hh), "white")
  18.  
  19. R = [''.join(comb) for comb in itertools.product('abcdefghij', repeat=3)]
  20. G = [''.join(comb) for comb in itertools.product('klmnopqrst', repeat=3)]
  21. B = [''.join(comb) for comb in itertools.product('tuvwxyzABC', repeat=3)]
  22. RRR = []
  23. GGG = []
  24. BBB = []
  25. for i in range(len(R)):
  26.     if len(set([R[i][0], R[i][1], R[i][2]])) == 3:
  27.         RRR += [R[i]]
  28.         GGG += [G[i]]
  29.         BBB += [B[i]]
  30.  
  31. x2 = 720.0/ww
  32. y2 = 720.0/hh
  33. buffer = []
  34. alpha = []
  35. for y in range(hh):
  36.     b = int(y*y2)
  37.     for x in range(ww):
  38.         a = int(x*x2)
  39.         c = (a+b) // 2
  40.         ttt = f'{RRR[a]}{GGG[b]}{BBB[c]}'
  41.         for i in range(len(ttt)-1):
  42.             t = ttt[i:i+2]
  43.             alpha.append(t)
  44.         buffer += [ttt]
  45.  
  46. alpha = sorted(list(set(alpha)))
  47.  
  48. colors = []
  49. for r in range(0,256,5):
  50.     for g in range(0,256,5):
  51.         for b in range(0,256,5):
  52.             colors += [(r,g,b)]
  53.            
  54. i = 0
  55. while 1:
  56.     rgb = []
  57.     rs(colors)
  58.     for z in buffer:
  59.         i = ri(0,7)
  60.         d = z[i]+z[i+1]
  61.         idx = alpha.index(d)
  62.         rgb += [colors[idx]]
  63.        
  64.     img.putdata(rgb)
  65.     image_tk = ImageTk.PhotoImage(img)
  66.     canvas.create_image(0,0,anchor=NW,image=image_tk)
  67.     root.update()
Add Comment
Please, Sign In to add comment