here2share

# Tk_rgb_automata.py

May 1st, 2021 (edited)
759
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_rgb_automata.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. from random import choice, randint, shuffle
  6.  
  7. COLORS = [  (255,0,0),
  8.             (0,255,0),
  9.             (0,0,255)]
  10.  
  11. Lc = len(COLORS)
  12.  
  13. def oRGB(rgb): # pass
  14.     r,g,b = rgb
  15.     return "#%02x%02x%02x" % (r,g,b)
  16.  
  17. ww = 500
  18. hh = 500
  19. root = Tk()
  20. root.title("Tk_rgb_automata")
  21. root.geometry("%dx%d+0+0"%(ww,hh))
  22. canvas = Canvas(root, width=ww, height=hh)
  23. canvas.grid()
  24.  
  25. limit = 5
  26. RGB_BALANCE = []
  27. LIMIT_BALANCE = [z%limit for z in range(ww)]
  28.  
  29. for color in COLORS:
  30.     t = COLORS[:]
  31.     t.remove(color)
  32.     ttt = []
  33.     for z in [color]+t:
  34.         ttt.extend([z]*((ww/(Lc*2))))
  35.     RGB_BALANCE.append(ttt)
  36.  
  37. img = Image.new("RGB",(ww, hh))
  38.  
  39. xScan = range(ww)
  40. __yScan = [z%limit for z in range(ww+20)]
  41.  
  42. def by_yScan(count):
  43.     yyy = yScan[:]
  44.     rgb_bal = [z[:] for z in RGB_BALANCE]
  45.     limit_bal = LIMIT_BALANCE[:]
  46.     shuffle(limit_bal)
  47.     #shuffle(xScan)
  48.     for i in xScan:
  49.         ttt = yyy[i:i+2]
  50.         try:
  51.             t,ccc = ddd[str(ttt)]
  52.         except:
  53.             if count:
  54.                 count -= 1
  55.                 ccc = ttt[1]%Lc
  56.             else:
  57.                 ccc = randint(0,Lc-1)
  58.             ddd[str(ttt)] = limit_bal.pop(), rgb_bal[ccc].pop(0)
  59.             t = ddd[str(ttt)][0]
  60.        
  61.         if not randint(0,force):
  62.             t = randint(0,limit)
  63.        
  64.         yScan[i+j%2] = t
  65.         rgb.append(ccc)
  66.     return count
  67.  
  68. while 1:
  69.     force = 60
  70.     yScan = __yScan[:]
  71.     shuffle(yScan)
  72.     count = int(ww*0.2)
  73.     rgb = []
  74.     ddd = {}
  75.     for j in range(0, hh):
  76.         count = by_yScan(count)
  77.     img.putdata(rgb)
  78.     imgTk = ImageTk.PhotoImage(img)
  79.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  80.     canvas.update()
  81.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×