Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_spiral_sort_2.py
- from Tkinter import *
- from math import sqrt
- 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_spiral_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
- def switch(state):
- return {
- 0 : (x + stepSize, y),
- 1 : (x, y - stepSize),
- 2 : (x - stepSize, y),
- 3 : (x, y + stepSize),
- }[state]
- # set up spiral
- step = 1
- state = 0
- numSteps = 1
- turnCounter = 1
- stepSize = 5
- cols = ww / stepSize
- rows = hh / stepSize
- totalSteps = cols * rows
- x = ww / 2
- y = hh / 2
- xy = []
- while 1:
- # Move according to state
- x,y = switch(state)
- xy.append((x,y))
- # Change state
- if step % numSteps == 0:
- state = (state + 1) % 4
- turnCounter += 1
- if turnCounter % 2 == 0:
- numSteps += 1
- step += 1
- if step > totalSteps:
- break
- COLORS = 'red orange yellow green blue purple'.split()
- t = stepSize
- i = 100
- iii = 1
- s = ''
- while 1:
- Lc = len(COLORS)
- canvas.delete('all')
- for x,y in xy:
- if len(s) < 10:
- s += str(i)
- i += 1
- iii = int(s[:3])
- s = s[3:]
- color = int(iii)%Lc
- canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement