Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_basic_spirograph.py
- import math
- import random
- from Tkinter import *
- ww = hh = 680
- ctr = ww/2
- root = Tk()
- root.title("# Tk_basic_spirograph")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- def e(n):
- return n if n else 1
- def drawSpiros(x, y, l):
- def draw():
- canvas.delete('all')
- canvas.create_line(xy[::-1], fill='red', width=1)
- canvas.update()
- def pxy():
- px = R*(1-k)*(math.cos(a) + l*k*math.cos((1-k)* a/e(k)))
- py = R*(1-k)*(math.sin(a) - l*k*math.sin((1-k)* a/e(k)))
- return -px,-py
- a = 0.0
- l *= 0.1
- r = 100
- incr = 50
- t = [5,0.5,0.05,0.001]
- end = t[-1]
- p = 0
- while 1:
- R = r*1.0*sides
- k = r/e(R)
- px,py = pxy()
- if abs(px) <= 300:
- if incr == end:
- break
- incr = t.pop(0)
- r = p
- p = r
- r -= incr
- # print incr
- xy = []
- for i in range(0, 360+10):
- a = math.radians(i)
- px,py = pxy()
- xy += [px + x, py + y]
- draw()
- for sides in range(3,25):
- print sides,'SIDES'
- for value in range(2,80+sides*50):
- drawSpiros(ctr, ctr, value**1.2)
Add Comment
Please, Sign In to add comment