Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_rgb_automata.py
- from Tkinter import *
- from PIL import Image, ImageTk
- from random import choice, randint, shuffle
- COLORS = [ (255,0,0),
- (0,255,0),
- (0,0,255)]
- Lc = len(COLORS)
- def oRGB(rgb): # pass
- r,g,b = rgb
- return "#%02x%02x%02x" % (r,g,b)
- ww = 500
- hh = 500
- root = Tk()
- root.title("Tk_rgb_automata")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- limit = 5
- RGB_BALANCE = []
- LIMIT_BALANCE = [z%limit for z in range(ww)]
- for color in COLORS:
- t = COLORS[:]
- t.remove(color)
- ttt = []
- for z in [color]+t:
- ttt.extend([z]*((ww/(Lc*2))))
- RGB_BALANCE.append(ttt)
- img = Image.new("RGB",(ww, hh))
- xScan = range(ww)
- __yScan = [z%limit for z in range(ww+20)]
- def by_yScan(count):
- yyy = yScan[:]
- rgb_bal = [z[:] for z in RGB_BALANCE]
- limit_bal = LIMIT_BALANCE[:]
- shuffle(limit_bal)
- #shuffle(xScan)
- for i in xScan:
- ttt = yyy[i:i+2]
- try:
- t,ccc = ddd[str(ttt)]
- except:
- if count:
- count -= 1
- ccc = ttt[1]%Lc
- else:
- ccc = randint(0,Lc-1)
- ddd[str(ttt)] = limit_bal.pop(), rgb_bal[ccc].pop(0)
- t = ddd[str(ttt)][0]
- if not randint(0,force):
- t = randint(0,limit)
- yScan[i+j%2] = t
- rgb.append(ccc)
- return count
- while 1:
- force = 60
- yScan = __yScan[:]
- shuffle(yScan)
- count = int(ww*0.2)
- rgb = []
- ddd = {}
- for j in range(0, hh):
- count = by_yScan(count)
- img.putdata(rgb)
- imgTk = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=NW, image=imgTk)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement