Advertisement
here2share

# Tk_basic_color_patterns.py

Nov 21st, 2022
1,920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # Tk_basic_color_patterns.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 = 5
  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. colors = 'red orange yellow green blue purple'.split()*(600*4)
  21. L = len(colors)
  22.  
  23. rgb = []
  24. xy = []
  25. for y in range(0,hh,sz):
  26.     for x in range(0,ww,sz):
  27.         xy += [(x,y)]
  28.         rgb += [0]
  29. Lxy = len(rgb)
  30.  
  31. i = 0
  32. while 1:
  33.     print (seq)
  34.     seq += 1
  35.     canvas.delete('all')
  36.     for k in range(Lxy):
  37.         color = colors[0]
  38.         colors.insert(L-i, colors.pop(0))
  39.         i = (i-1)%99
  40.         x,y = xy[k]
  41.         canvas.create_rectangle((x, y, x-sz, y+sz), fill=color, width=0)
  42.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement