Advertisement
here2share

# Tk_grayscale_patterns.py

Nov 25th, 2022
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. # Tk_grayscale_patterns.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import math
  6. from itertools import combinations
  7.  
  8. ww = 500
  9. hh = 500
  10.  
  11. sz = 10
  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.  
  19. t = range(0,256,25)
  20. TTT = []
  21. for grey in t:
  22.     TTT += [(grey, grey, grey)]
  23. TTT *= (ww+hh)
  24.  
  25. xy = []
  26. for y in range(0,hh,sz):
  27.     for x in range(0,ww+1,sz):
  28.         xy += [(x,y)]
  29.  
  30. o = [i for i in range(255)]
  31. o = o[1:-1] + o[::-1]
  32. L = len(o)
  33.  
  34. def make_rgb():
  35.     return '#%02X%02X%02X'%(r,g,b)
  36.  
  37. aaa = []
  38. bbb = []
  39. i = 0
  40. seq = 1 # sequences
  41. sub = 1
  42. while 1:
  43.     ttt = TTT[:]
  44.     if (bbb in aaa) or (sub > 25):
  45.         aaa = []
  46.         seq += 1
  47.         sub = 1
  48.     print (seq, sub)
  49.     aaa += [bbb[:]]
  50.     bbb = []
  51.     canvas.delete('all')
  52.     for x,y in xy:
  53.         r,g,b = ttt.pop(-i)
  54.         bbb += [r]
  55.         i = (i-1)%seq
  56.         canvas.create_rectangle((x, y, x-sz, y+sz), fill=make_rgb(), width=0)
  57.     sub += 1
  58.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement