Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_rgb_sq_spiral.py
- from Tkinter import *
- from math import sqrt
- def oRGB(rgb): # pass
- r,g,b = rgb
- return "#%02x%02x%02x" % (r,g,b)
- ww = 600
- hh = 600
- root = Tk()
- root.title("# Tk_rgb_sq_spiral")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.grid()
- def switch(state):
- return {
- 0 : (x + stepSize, y),
- 1 : (x, y - stepSize),
- 2 : (x - stepSize, y),
- 3 : (x, y + stepSize),
- }[state]
- # to record spiral
- xy = []
- # 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
- o256 = range(0,256,10)
- rgb = [(r,g,b) for r in o256 for g in o256 for b in o256][::-1]
- while 1:
- xy.append((x,y))
- # Change state
- if step % numSteps == 0:
- state = (state + 1) % 4
- turnCounter += 1
- if turnCounter % 2 == 0:
- numSteps += 1
- step += 1
- x, y = switch(state)
- # Are we done?
- if step > totalSteps:
- break
- step = 20
- for x,y in xy:
- t = stepSize
- color = oRGB(rgb[step])
- canvas.create_rectangle((x,y,x+t,y+t), fill=color, outline='')
- step += 1
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement