Advertisement
here2share

# Tk_trinary_art_attempt.py

Sep 25th, 2021
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # Tk_trinary_art_attempt.py
  2.  
  3. from Tkinter import *
  4. import random, time
  5. from itertools import permutations
  6.  
  7. ww = 200
  8. hh = 300
  9. root = Tk()
  10. root.title("Tk_trinary_art_attempt")
  11. root.geometry("%dx%d+0+0"%(ww,hh))
  12.  
  13. def rgb2hex(r,g,b):
  14.     return '#%02X%02X%02X'%(r,g,b)
  15.  
  16. def draw():
  17.     canvas.delete()
  18.     for y in range(hh):
  19.         for x in move:
  20.             x = x+y%6
  21.             t = tuple(scan[x:x+3])
  22.             try:
  23.                 t = magic[t]
  24.                 scan[x:x+3] = t
  25.             except:
  26.                 scan[x],scan[0] = scan[0],scan[x]
  27.                
  28.         for x in range(6,Lscan-6):
  29.             t = scan[x]
  30.             canvas.create_rectangle((x-6,y,x-6,y), fill=COLORS[t%Lcolors], outline='')
  31.     canvas.update()
  32. 0
  33.  
  34. canvas = Canvas(root, width=ww, height=hh)
  35. canvas.pack()
  36.  
  37. COLORS = 'red orange yellow green blue purple'.split()
  38. Lcolors = len(COLORS)
  39. magic = list(permutations(range(Lcolors), 3))
  40. scan = range(Lcolors)*(ww/Lcolors+20)
  41. Lscan = len(scan)
  42. move = range(0,Lscan,6)
  43.  
  44. while 1:
  45.     magic = [((a,b,c),random.choice(((a,b,c),(a,c,b),(b,a,c),(b,c,a),(c,a,b),(c,b,a)))) for a,b,c in magic]
  46.     magic = dict(magic)
  47.     random.shuffle(move)
  48.     random.shuffle(scan)
  49.  
  50.     draw()
  51. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement