Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_spiral_of_9_integers.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_of_9_integers")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- def isOf3(num):
- for a in Random3:
- if not num%a:
- return False
- return num > 3
- def switch(state):
- return {
- 0 : (x + stepSize, y),
- 1 : (x, y - stepSize),
- 2 : (x - stepSize, y),
- 3 : (x, y + stepSize),
- }[state]
- forRandom3 = [z for z in range(7,2000)]
- while 1:
- rs(forRandom3)
- Random3 = forRandom3[:9]
- print Random3
- for L in range(7,18):
- # 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
- try: canvas.delete('all')
- except: 0
- while 1:
- # If prime... draw
- if isOf3(step):
- color = (color + 1) % L
- t = stepSize * 0.5
- canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
- # Move according to state
- x, y = switch(state)
- # Change state
- if step % numSteps == 0:
- state = (state + 1) % 4
- turnCounter += 1
- if turnCounter % 2 == 0:
- numSteps += 1
- step += 1
- # Are we done?
- if step > totalSteps:
- break
- canvas.update()
- rs(COLORS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement