Advertisement
here2share

# Tk_sq_combos.py

Dec 5th, 2020
1,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. # Tk_sq_combos.py -- just an experiment
  2.  
  3. from Tkinter import *
  4.  
  5. # Number of squares in x and y dimensions.
  6. nx = 80
  7. ny = 80
  8.  
  9. # Size of square side in pixels.
  10. ss = 5
  11.  
  12. # Total dimensions of display.
  13. ww = nx * ss
  14. hh = ny * ss
  15.  
  16. root = Tk()
  17. root.geometry("%sx%s+0+0" % (ww, hh))
  18. c = Canvas(root, width=ww, height=hh)
  19. c.pack()
  20.  
  21. COLORS = 'blue purple black gray white '.split()
  22. val = 'qwertyuiopasdfghjklzxcvbnm1234567890'
  23.  
  24. from itertools import combinations
  25.  
  26. combos = [p for p in combinations(COLORS*3, 7)]
  27.  
  28. def make_square(x, y, color):
  29.     return c.create_rectangle(x * ss, y * ss, (x+1) * ss, (y+1) * ss,
  30.                               fill=color, outline=color)
  31.  
  32. def make_squares():
  33.     squares = []
  34.     for x in range(nx):
  35.         squares.append([])
  36.         for y in range(ny):
  37.             squares[x].append(make_square(x, y, 'white'))
  38.     return squares
  39.  
  40. squares = make_squares()
  41.  
  42. done = False
  43. def quit_handler(event):
  44.     global done
  45.     done = True
  46.  
  47. # Left mouse button click on canvas terminates the program.
  48. root.bind('<Button-1>', quit_handler)
  49.  
  50. ppp = []
  51. while not done:
  52.     sss = ''
  53.     for x in range(len(squares)):
  54.         for y in range(len(squares[x])):
  55.             h = squares[x][y]
  56.             t = -11
  57.             while 1:
  58.                 if not ppp:
  59.                     ppp = list(combos.pop(0))+COLORS
  60.                     combos.append(ppp[:])
  61.                     t -= 1
  62.                 p = ppp.pop()
  63.                 s = val[COLORS.index(p)]
  64.                 if sss[t:]+s not in sss:
  65.                     break
  66.             sss += s
  67.             sss = sss[-ww*hh:]
  68.             color = p
  69.             c.itemconfig(h, fill=color, outline=color)
  70.     combos = combos + [combos.pop(9),combos.pop(7),combos.pop(3),combos.pop(0)]
  71.     root.update()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement