Advertisement
here2share

# Tk_no_ones_2.py

Feb 26th, 2022
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. # Tk_no_ones_2.py
  2.  
  3. from Tkinter import *
  4. from math import sqrt, atan2
  5. from random import shuffle as rs
  6.  
  7. def oRGB(rgb): # pass
  8.     r,g,b = rgb
  9.     return "#%02x%02x%02x" % (r,g,b)
  10.  
  11. ww = 600
  12. hh = 600
  13. root = Tk()
  14. root.title("# Tk_no_ones_2")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  16. canvas = Canvas(root, width=ww, height=hh)
  17. canvas.grid()
  18.  
  19. def isAlive(num):
  20.     for a in RandomAlive:
  21.         if not num%a:
  22.             return RandomAlive.index(a)
  23.     return (color + 7) % 12
  24.  
  25.  
  26. def switch(state):
  27.     return {
  28.         0 : (x + stepSize, y),
  29.         1 : (x, y - stepSize),
  30.         2 : (x - stepSize, y),
  31.         3 : (x, y + stepSize),
  32.     }[state]
  33.    
  34.    
  35. # set up spiral
  36. step = 1
  37. state = 0
  38. numSteps = 1
  39. turnCounter = 1
  40. stepSize = 5
  41. cols = ww / stepSize
  42. rows = hh / stepSize
  43. totalSteps = cols * rows
  44. x0 = ww / 2
  45. y0 = hh / 2
  46.  
  47. COLORS = 'red orange yellow green blue purple'.split()
  48. t = stepSize
  49. i = 12345
  50. iii = 0
  51. ttt = 0
  52. s = ''
  53. Lc = len(COLORS)
  54. while 1:
  55.     canvas.delete('all')
  56.     for y in range(0,hh,stepSize):
  57.         for x in range(0,ww,stepSize):
  58.             while 1:
  59.                 if len(s) < 100:
  60.                     s += str(i).replace('1','')
  61.                     i += 1
  62.                 if s:
  63.                     if ttt < 1:
  64.                         ttt = iii = int(s[:2])
  65.                         s = s[2:]
  66.                         color = int(iii)%Lc
  67.                     canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
  68.                     break
  69.             ttt -= 1
  70.            
  71.     canvas.update()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement