Advertisement
here2share

# Tk_AquaticSponge.py

Dec 7th, 2019
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. # Tk_AquaticSponge.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. import time
  7.  
  8. w = h = 200
  9.  
  10. pp = [(x,y) for x in xrange(w) for y in xrange(h)]
  11. random.shuffle(pp)
  12.  
  13. xy = [z%254 for z in xrange(w*h)]
  14. xy.sort()
  15.  
  16. def climb(x,y):
  17.     t = x%2 # to double the speed
  18.     if t:
  19.         z = [(x+1, y), (x, y+1), (x, y-1), (x-1, y)]
  20.     else:
  21.         z = [(x+1, y+1), (x+1, y-1), (x-1, y+1), (x-1, y-1)]
  22.     random.shuffle(z)
  23.     return z
  24.  
  25. root = Tk()
  26. root.title("Tk Aquatic Sponge")
  27. canvas = Canvas(root, width=w, height=h, bg='black')
  28. canvas.pack()
  29.  
  30. peaks = 10
  31. rnd_peaks = [0 for z in range(1,int(w*h*0.8))]+range(1,10)+[1]
  32. random.shuffle(rnd_peaks)
  33. zzz,pp = pp[:peaks],pp[peaks:]
  34. aaa = zzz[:]
  35. t = 0
  36. while 1:
  37.     if aaa:
  38.         x,y = aaa.pop(0)
  39.         try:
  40.             ccc = '#%02x%02x%02x' % tuple([xy.pop()]*3)
  41.         except:
  42.             break
  43.         canvas.create_line((x,y,x+1,y), fill=ccc)
  44.         ppp = climb(x,y)
  45.         for z in ppp[:2]:
  46.             try:
  47.                 aaa.append(pp.pop(pp.index(z)))
  48.             except:
  49.                 0
  50.         for z in ppp[2:]:
  51.             try:
  52.                 zzz.append(pp.pop(pp.index(z)))
  53.             except:
  54.                 0
  55.         if rnd_peaks.pop():
  56.             aaa = [pp.pop()] + aaa
  57.     else:
  58.         aaa,zzz = zzz[:100],zzz[100:]
  59.         random.shuffle(aaa)
  60.     if t < time.time():
  61.         print len(pp)
  62.         t = time.time()+5
  63.     root.update()
  64. 0
  65. print '***'
  66. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement