Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_radial_sort_2.py
- from Tkinter import *
- from math import sqrt, atan2
- from random import shuffle as rs
- def oRGB(rgb): # pass
- r,g,b = rgb
- return "#%02x%02x%02x" % (r,g,b)
- COLORS = 'red orange yellow green blue purple'.split()*5
- color = 0
- ww = 600
- hh = 600
- root = Tk()
- root.title("# Tk_radial_sort_2")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- def isAlive(num):
- for a in RandomAlive:
- if not num%a:
- return RandomAlive.index(a)
- return (color + 7) % 12
- # to record spiral
- stepSize = 5
- cols = ww / stepSize
- rows = hh / stepSize
- x = x0 = ww / 2
- y = y0 = hh / 2
- xy = []
- for y in range(0,hh,stepSize):
- for x in range(0,ww,stepSize):
- distance = sqrt((x0-x)**2+(y0-y)**2)
- xy2 = atan2(x-x0,y-y0)
- xy.append(((int(distance), xy2),x,y))
- xy.sort()
- xy = [(x,y) for z,x,y in xy]
- forRandomAlive = [z for z in range(7,5000)]
- step = 1
- while 1:
- rs(forRandomAlive)
- RandomAlive = forRandomAlive[:12]
- RandomAlive.sort(reverse=1)
- print RandomAlive
- canvas.delete('all')
- for x,y in xy:
- color = isAlive(step)
- t = stepSize
- canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
- step += 1
- canvas.update()
- rs(COLORS)
Add Comment
Please, Sign In to add comment