import turtle import math from Tkinter import * # Set up the TK frame root = Tk() fram = Frame(root) canv = Canvas(root,width=640,height=480) canv.pack(side=TOP,fill=BOTH,expand=1) # Number of frames to generate count = 300.0 for dx in xrange(0, (int)(count)): # Create sinusoidal counter cx = (count*(1.1+math.sin(((dx*math.pi)/count)-math.pi/2.0))/2.11) print "dx = "+str(dx)+" cx = "+str(cx) print "Generating frame "+str(dx) canv.delete(ALL) canv.config(background="white") # Draw central line turtle1 = turtle.RawPen(canv) turtle1.tracer(False) turtle1.up() turtle1.goto(0,-220) turtle1.left(90) turtle1.down() turtle1.forward((int)((150.0/count)*(int)(cx))) # Define branching factor branchingfactor = (int)(math.floor(2.0+13.0*(cx/count))) # Create description of the fractal set="A" for i in range(branchingfactor): set=set.replace("A","LFsASFrFsASFL") i = 1 turtle1.forward(20) for move in set: if move is "A": turtle1.left(180) branchlength = 20.0+(80.0*(cx/count)) branchscale = 2.0 - (0.75*(cx/count)) if move is "F": turtle1.forward((int)(branchlength/branchscale**i)) if move is "L": turtle1.left(45) if move is "r": turtle1.left(90) if move is "s": i+=1 if move is "S": i-=1 # Save frame as PS file filename = str(dx) if len(filename)==1: filename = "00"+filename if len(filename)==2: filename = "0"+filename canv.postscript(file="output/"+filename+".ps", x=0, y=0, height=480, width=640)