#Computer fly algorithm by C. Pickover from Math 198 Course Notes #Modified from program in Python/Tkinter by William Baker #Emily Gunawan, Summer 2004, illiMath04 Program #University of Illinois Urbana-Champaign Dept. of Math #corrected in myfly.py by gkf 28dec04 import Tkinter import math import time defaldelay=1 #default delay time #******************************************************************************# length=3.0 #set "pixel" square to length x length mag=110.0 #magnification factor x0=400.0 ; y0=300.0 #(0,0) position on the x,y axis width=x0*2 ; height=2*y0 #******************************************************************************# def pixset(x,y): #set a blue box at (x,y) x=x0 + x*mag ; y= y0+y*mag canvas.create_rectangle(x,y,x+length,y+length,fill="blue") #******************************************************************************# def startAnimation(): #start animation when the start button is clicked h=0.1 a=2.24 ; b=0.43 ; c=-0.65; d=-2.0 e=0.75 x,y,z=0,0,0 for j in range(100): for i in range(75): if abs(x)>width/2.0 and abs(y)>length/2.0: break x1=math.sin(a*y)-z*math.cos(b*x) y1=z*math.sin(c*x)-math.cos(d*y) z1=e*math.sin(x) x=x1 y=y1 z=z1 pixset(x1,y1) canvas.update() time.sleep(int(timedelay.get())/20.0) #******************************************************************************# def clear(): #clears the canvas when the clear button is clicked canvas.delete("all") #******************************************************************************# window = Tkinter.Tk() window.title("'Nodal Points, Polar calculation, in Python/Tkinter") clear_button = Tkinter.Button(window, text = "Clear", command = clear) start = Tkinter.Button(window, text="Start", command=startAnimation) delLabel=Tkinter.Label(window, width="15") delLabel.configure(text="Time Delay= ") timedelay=Tkinter.StringVar() timedelay.set(`defaldelay`) delentry = Tkinter.Entry(window, width="15", textvariable=timedelay) canvas = Tkinter.Canvas(window, width=x0*2, height=2*y0) canvas.pack(side="top") delLabel.pack(side="left") delentry.pack(side="left") start.pack(side="right") clear_button.pack(side = "right") canvas.create_line(0,y0,2*x0,y0, fill="pink") #x-axis canvas.create_line(x0,0,x0,2*y0, fill="orange") #y-axis window.mainloop() #start event loop