here2share

# Tk_no_ones_and_twos_sq_spiral.py

Feb 26th, 2022 (edited)
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. # Tk_not_1_2_3_sq_spiral.py
  2.  
  3. from Tkinter import *
  4. from math import sqrt
  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_not_1_2_3_sq_spiral")
  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. x = ww / 2
  45. y = hh / 2
  46.  
  47. xy = []
  48. while 1:
  49.     xy.append((x,y))
  50.    
  51.     # Change state
  52.     if step % numSteps == 0:
  53.         state = (state + 1) % 4
  54.         turnCounter += 1
  55.         if turnCounter % 2 == 0:
  56.             numSteps += 1
  57.     step += 1
  58.     x, y = switch(state)
  59.  
  60.     # Are we done?
  61.     if step > totalSteps:
  62.         break
  63.  
  64. COLORS = 'red orange yellow green blue purple'.split()
  65. t = stepSize
  66. i = 12345
  67. iii = 1
  68. s = ''
  69. Lc = len(COLORS)
  70. while 1:
  71.     canvas.delete('all')
  72.     for x,y in xy:
  73.         while 1:
  74.             if len(s) < 100:
  75.                 s += str(i).replace('1','').replace('2','').replace('3','')
  76.                 i += 1
  77.             if s:
  78.                 iii = int(s[:4])
  79.                 s = s[4:]
  80.                 color = int(iii)%Lc
  81.                 canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
  82.                 break
  83.            
  84.     canvas.update()
  85.  
Add Comment
Please, Sign In to add comment