here2share

# Tk_quasi_colors.py

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