here2share

# Tk_radial_sort_2.py

Feb 22nd, 2022 (edited)
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # Tk_radial_sort_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. COLORS = 'red orange yellow green blue purple'.split()*5
  12. color = 0
  13.  
  14. ww = 600
  15. hh = 600
  16. root = Tk()
  17. root.title("# Tk_radial_sort_2")
  18. root.geometry("%dx%d+0+0"%(ww,hh))
  19. canvas = Canvas(root, width=ww, height=hh)
  20. canvas.grid()
  21.  
  22. def isAlive(num):
  23.     for a in RandomAlive:
  24.         if not num%a:
  25.             return RandomAlive.index(a)
  26.     return (color + 7) % 12
  27.  
  28. # to record spiral
  29. stepSize = 5
  30. cols = ww / stepSize
  31. rows = hh / stepSize
  32. x = x0 = ww / 2
  33. y = y0 = hh / 2
  34. xy = []
  35. for y in range(0,hh,stepSize):
  36.     for x in range(0,ww,stepSize):
  37.         distance = sqrt((x0-x)**2+(y0-y)**2)
  38.         xy2 = atan2(x-x0,y-y0)
  39.         xy.append(((int(distance), xy2),x,y))
  40.        
  41. xy.sort()
  42. xy = [(x,y) for z,x,y in xy]
  43.    
  44. forRandomAlive = [z for z in range(7,5000)]
  45.  
  46. step = 1
  47. while 1:
  48.     rs(forRandomAlive)
  49.     RandomAlive = forRandomAlive[:12]
  50.     RandomAlive.sort(reverse=1)
  51.     print RandomAlive
  52.    
  53.     canvas.delete('all')
  54.    
  55.     for x,y in xy:
  56.         color = isAlive(step)
  57.         t = stepSize
  58.         canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
  59.         step += 1
  60.     canvas.update()
  61.     rs(COLORS)
Add Comment
Please, Sign In to add comment