Advertisement
here2share

# Tk_no_ones_radial_2.py

Feb 26th, 2022
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. # Tk_no_ones_radial_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_radial")
  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. xy = []
  48. for y in range(0,hh,stepSize):
  49.     for x in range(0,ww,stepSize):
  50.         distance = sqrt((x0-x)**2+(y0-y)**2)
  51.         xy2 = atan2(x-x0,y-y0)
  52.         xy.append(((int(distance), xy2),x,y))
  53.        
  54. xy.sort()
  55.  
  56. xy = [(x,y) for z,x,y in xy]
  57.  
  58.  
  59. COLORS = 'red orange yellow green blue purple'.split()
  60. t = stepSize
  61. i = 12345
  62. iii = 0
  63. ttt = 0
  64. s = ''
  65. Lc = len(COLORS)
  66. while 1:
  67.     canvas.delete('all')
  68.     for x,y in xy:
  69.         while 1:
  70.             if len(s) < 100:
  71.                 s += str(i).replace('1','')
  72.                 i += 1
  73.             if s:
  74.                 if ttt < 1:
  75.                     ttt = iii = int(s[:2])
  76.                     s = s[2:]
  77.                     color = int(iii)%Lc
  78.                 canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
  79.                 break
  80.         ttt -= 1
  81.            
  82.     canvas.update()
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement