here2share

# Tk_quasi_colors_2.py

Nov 21st, 2022
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. # Tk_quasi_colors_2.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import math
  6. from itertools import combinations
  7.  
  8. ww = 600
  9. hh = 600
  10.  
  11. sz = 30
  12.  
  13. root = Tk()
  14. root.geometry("%dx%d+0+0"%(ww,hh))
  15. canvas = Canvas(root, width=ww, height=hh)
  16. canvas.pack()
  17.  
  18. seq = 1 # sequences
  19.  
  20. t = range(14)
  21. ttt = []
  22. for r in t:
  23.     for g in t:
  24.         for b in t:
  25.             ttt += [(r,g,b)]
  26. ttt = sorted(ttt, key=sum)
  27. ttt.pop(0)
  28. Lt = len(ttt)
  29.  
  30. cc = {}
  31. for x in range(ww):
  32.     for y in range(hh):
  33.         cc[x,y] = 0
  34.  
  35. rgb = []
  36. xy = []
  37. x2 = 256.0/ww
  38. y2 = 256.0/hh
  39. for y in range(0,hh,sz):
  40.     b = int(y*y2)
  41.     for x in range(0,ww,sz):
  42.         a = int(x*x2)
  43.         c = cc[a,b]
  44.         rgb += [(a,b,c)]
  45.         cc[a,b] = c+1
  46.         xy += [(x,y)]
  47.  
  48. del cc # cc deleted
  49.  
  50. img = Image.new("RGB",(ww,hh), "white")
  51.  
  52. o = [i for i in range(255)]
  53. o = o[1:-1] + o[::-1]
  54. L = len(o)
  55. def make_rgb():
  56.     return '#%02X%02X%02X'%(o[int(r%L)],o[int(g%L)],o[int(b%L)])
  57.  
  58. i = 0
  59. while 1:
  60.     print (seq)
  61.     seq += 1
  62.     canvas.delete('all')
  63.     for k, (rrr,ggg,bbb) in enumerate(rgb):
  64.         r2,g2,b2 = ttt[0]
  65.         ttt.insert(Lt-i, ttt.pop(0))
  66.         i = (i-1)%3
  67.         r,g,b = (rrr+r2,ggg+g2,bbb+b2)
  68.         rgb[k] = r,g,b
  69.         x,y = xy[k]
  70.         canvas.create_rectangle((x, y, x-sz, y+sz), fill=make_rgb(), width=0)
  71.     canvas.update()
Add Comment
Please, Sign In to add comment