Advertisement
here2share

# Tk_no_ones_sq_spiral_3.py

Feb 26th, 2022
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. # Tk_no_ones_sq_spiral_3.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_sq_spiral_3")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  16. canvas = Canvas(root, width=ww, height=hh)
  17. canvas.grid()
  18.  
  19. def switch(state):
  20.     return {
  21.         0 : (x + stepSize, y),
  22.         1 : (x, y - stepSize),
  23.         2 : (x - stepSize, y),
  24.         3 : (x, y + stepSize),
  25.     }[state]
  26.  
  27. # set up spiral
  28. step = 1
  29. state = 0
  30. numSteps = 1
  31. turnCounter = 1
  32. stepSize = 5
  33. cols = ww / stepSize
  34. rows = hh / stepSize
  35. totalSteps = cols * rows
  36. x = ww / 2
  37. y = hh / 2
  38.  
  39. xy = []
  40. while 1:
  41.     xy.append((x,y))
  42.    
  43.     # Change state
  44.     if step % numSteps == 0:
  45.         state = (state + 1) % 4
  46.         turnCounter += 1
  47.         if turnCounter % 2 == 0:
  48.             numSteps += 1
  49.     step += 1
  50.     x, y = switch(state)
  51.  
  52.     # Are we done?
  53.     if step > totalSteps:
  54.         break
  55.  
  56. COLORS = 'red orange yellow green blue purple'.split()
  57. t = stepSize
  58. i = 12345
  59. iii = 0
  60. ttt = 0
  61. s = ''
  62. Lc = len(COLORS)
  63. while 1:
  64.     canvas.delete('all')
  65.     for x,y in xy:
  66.         while 1:
  67.             if len(s) < 100:
  68.                 s += str(i).replace('1','')
  69.                 i += 1
  70.             if s:
  71.                 if ttt < 1:
  72.                     ttt = iii = int(s[:2])
  73.                     s = s[2:]
  74.                     color = int(iii)%Lc
  75.                 canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
  76.                 break
  77.         ttt -= 1
  78.            
  79.     canvas.update()
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement