Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_spiralgram.py
- from Tkinter import *
- import math
- root = Tk()
- ww = 520
- hh = 520
- r = (min(ww,hh)-5)/2
- canvas = Canvas(root,width=ww,height=hh)
- canvas.pack()
- rainbow = []
- def rgb():
- rainbow.append('#{:02x}{:02x}{:02x}'.format(r,g,b))
- r, g, b = 255, 0, 0
- for g in range(256):
- rgb()
- for r in range(255, -1, -1):
- rgb()
- for b in range(256):
- rgb()
- for g in range(255, -1, -1):
- rgb()
- for r in range(256):
- rgb()
- for b in range(255, -1, -1):
- rgb()
- p = len(rainbow)/360.0
- r360 = [rainbow[int(z*p)] for z in range(360)]
- points = []
- circ = int(math.pi * r**2) / 20
- p = 360.0/circ
- print circ
- for x in range(0,ww,2):
- for y in range(x%2,hh,2):
- canvas.create_rectangle((x,y,x+2,y+2),fill='gray',outline=None)
- for t in range(circ):
- t *= p
- x = math.sin(t) + math.sin(6*t)/2 + math.cos(14*t)/3
- y = math.cos(t) + math.cos(6*t)/2 + math.sin(14*t)/3
- angle = math.degrees(math.atan2(x,y))
- x,y = [z*140+r-5 for z in (x,y)]
- color = r360[int(angle)]
- canvas.create_oval((x,y,x+1,y+1),fill=color,outline=color)
- canvas.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement