Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_sq_combos.py -- just an experiment
- from Tkinter import *
- # Number of squares in x and y dimensions.
- nx = 80
- ny = 80
- # Size of square side in pixels.
- ss = 5
- # Total dimensions of display.
- ww = nx * ss
- hh = ny * ss
- root = Tk()
- root.geometry("%sx%s+0+0" % (ww, hh))
- c = Canvas(root, width=ww, height=hh)
- c.pack()
- COLORS = 'blue purple black gray white '.split()
- val = 'qwertyuiopasdfghjklzxcvbnm1234567890'
- from itertools import combinations
- combos = [p for p in combinations(COLORS*3, 7)]
- def make_square(x, y, color):
- return c.create_rectangle(x * ss, y * ss, (x+1) * ss, (y+1) * ss,
- fill=color, outline=color)
- def make_squares():
- squares = []
- for x in range(nx):
- squares.append([])
- for y in range(ny):
- squares[x].append(make_square(x, y, 'white'))
- return squares
- squares = make_squares()
- done = False
- def quit_handler(event):
- global done
- done = True
- # Left mouse button click on canvas terminates the program.
- root.bind('<Button-1>', quit_handler)
- ppp = []
- while not done:
- sss = ''
- for x in range(len(squares)):
- for y in range(len(squares[x])):
- h = squares[x][y]
- t = -11
- while 1:
- if not ppp:
- ppp = list(combos.pop(0))+COLORS
- combos.append(ppp[:])
- t -= 1
- p = ppp.pop()
- s = val[COLORS.index(p)]
- if sss[t:]+s not in sss:
- break
- sss += s
- sss = sss[-ww*hh:]
- color = p
- c.itemconfig(h, fill=color, outline=color)
- combos = combos + [combos.pop(9),combos.pop(7),combos.pop(3),combos.pop(0)]
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement