Advertisement
here2share

# Tk_Migrate.py

Nov 3rd, 2021
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. # Tk_Migrate.py
  2.  
  3. from Tkinter import *
  4. from math import floor
  5. import time
  6. import random
  7.  
  8. ri = random.randint
  9. rs = random.shuffle
  10. rc = random.choice
  11.  
  12. tx =  time.time
  13. ww = 600
  14. hh = 600
  15.  
  16. root = Tk()
  17. root.title("Tk_Migrate")
  18. root.geometry("%dx%d+-6+-2"%(ww,hh))
  19. cv = Canvas(width=ww, height=hh, bg='black')
  20. cv.pack()
  21.  
  22. r = 10
  23. r2 = 3
  24.  
  25. ww = ww / r + 1
  26. hh = hh / r + 1
  27.  
  28. def rgb2hex(r,g,b):
  29.     return '#%02X%02X%02X'%(r,g,b)
  30.  
  31. gradient = [rgb2hex(0,0,0) for z in range(50)]
  32. gradient += [rgb2hex(0,z,0) for z in range(0,256,4)]
  33.  
  34. gradient = gradient[1:-1]+gradient[::-1]
  35. L = len(gradient)
  36.  
  37. cv_grid = dict([((x, y), 0) for x in range(ww) for y in range(hh)])
  38.  
  39. area = ','.join(['(x+'+str(x)+',y+'+str(y)+')' for x in range(10) for y in range(10)])
  40. area = eval('lambda x,y: ['+area+']')
  41.  
  42. balance = bal = [(x, y) for x in range(-5,ww) for y in range(-5,hh)]
  43.  
  44. def bloom(x, y):
  45.     try:
  46.         cv_grid[x, y] += 21
  47.         zzz = [ [x + 1, y],
  48.                 [x + 1, y],
  49.                 [x, y + 1],
  50.                 [x, y - 1]]
  51.         for a,b in zzz:
  52.             cv_grid[a, b] = cv_grid[a, b] + (cv_grid[a, b] * 0.001)        
  53.     except:
  54.         0
  55.  
  56. while 1:
  57.     if not bal:
  58.         bal = balance[:]
  59.     rs(bal)
  60.     x,y = bal.pop()
  61.     xy = area(x,y)
  62.     rs(xy)
  63.     for x,y in xy:
  64.         bloom(x, y)
  65.         try:
  66.             cv_grid[x, y] %= L
  67.             xy = cv_grid[x, y]
  68.             rgb = gradient[int(xy)]
  69.             cv.create_oval((x*r-r2,y*r-r2,x*r+r2,y*r+r2),fill=rgb,outline='')
  70.             cv.update()
  71.         except:
  72.             0
  73.    
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement