Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_radial_sort.py
- from Tkinter import *
- import math
- 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")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- xy = []
- PI = math.pi
- ww0 = ww/2
- hh0 = hh/2
- for r in range(1,500,5):
- circumference = (r * 2 * PI) / ((r + 200.0) / 50)
- if not circumference:
- circumference = 1
- for degrees in range(0,360,int(360.0/circumference)):
- angle = math.radians(degrees)
- x = int(r * math.cos(angle))+ww0
- y = int(r * math.sin(angle))+hh0
- if 0 < x < ww-6 and 0 < y < hh-6:
- xy.append((x,y))
- canvas.create_oval(x,y,x+8,y+8, fill="purple", outline="")
- canvas.update()
- def isAlive(num):
- for a in RandomAlive:
- if not num%a:
- return RandomAlive.index(a)
- return (color + 7) % 12
- def switch(state):
- return {
- 0 : (x + stepSize, y),
- 1 : (x, y - stepSize),
- 2 : (x - stepSize, y),
- 3 : (x, y + stepSize),
- }[state]
- forRandomAlive = [z for z in range(3,2000)]
- while 1:
- rs(forRandomAlive)
- RandomAlive = forRandomAlive[:12]
- RandomAlive.sort(reverse=1)
- print RandomAlive
- # set up spiral
- step = 1
- canvas.delete('all')
- for x,y in xy:
- color = isAlive(step)
- canvas.create_oval(x,y,x+8,y+8, fill=COLORS[color], outline="")
- step += 1
- canvas.update()
- rs(COLORS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement