Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_automata.py
- from Tkinter import *
- from PIL import Image, ImageTk
- import re
- import random
- ww = 600
- hh = 600
- root = Tk()
- root.title("Tk_automata")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- PIXELS = [(0,0,0)]*ww
- def draw():
- img.putdata(data)
- imgTk = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=NW, image=imgTk)
- root.update()
- def io(n):
- return "{0:08b}".format(n)
- '''
- IO = []
- t = ''
- c = 0
- while t != '11111':
- t = io(c)[-5:]
- if t[2] == '1':
- IO += [t]
- print t
- c += 1
- print IO
- '''
- SIDES__='1100 1110 1111 1010 1011'.split()
- def step(color=''):
- zzz = list(current)
- for ttt in list(re.finditer('1', current[1:-1])):
- if color:
- try:
- p[ttt.start()+ww/2-L/2] = color
- except:
- return
- else:
- t = random.randint(0,ww*2)
- if t < iii[0]:
- iii[0] = 0
- zzz[t+1:t+4] = random.choice(IO)
- t = ttt.start()-1
- b = current[t:t+5]
- if len(b) < 5:
- continue
- i = list(IO[IO.index(b)+1])
- zzz[t+1:t+4] = i
- '''
- '''
- zzz = zzz[1:]+zzz[:1]
- sides = random.choice(SIDES__)
- return sides+(''.join(zzz))[1:ww]+sides[::-1]
- IO__ = ['11111', '10111', '00100', '01110', '11100', '10110', '10100', '11101', '01111', '00110', '00101', '11110', '10101', '01101', '00111', '01100']
- def again(e):
- global go
- go=0
- root.bind('<space>', again)
- go=1
- iii = [0]
- while 1:
- IO = IO__[:]
- random.shuffle(IO)
- IO.append(IO[0])
- print IO
- print
- blk = [(0,0,0)]*(ww*hh)
- pix = []
- current = '1'
- prev = ''
- polar = 1
- img = Image.new("RGB",(ww, hh))
- while go:
- L = len(current)
- if L > ww:
- p = PIXELS[:]
- step((0,255,0))
- pix.extend(p)
- data = (pix)[-ww*hh:]
- draw()
- current = step()
- iii[0] += 1
- go = 1
Add Comment
Please, Sign In to add comment