#Bresenham Circle from "Jim Blinn's Corner" on "Graph Paper" #Modified from program in Python/Tkinter by William Baker #Emily Gunawan, Summer 2004, illiMath04 Program #University of Illinois Urbana-Champaign Dept. of Math import Tkinter import math import time defaldelay=4 #default delay time #******************************************************************************# mag=10 #magnification of the quadrille paper x0=400.0 ; y0=300.0 #(0,0) position on the x,y axis #******************************************************************************# 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+mag,y+mag,fill="blue") #******************************************************************************# def startAnimation(): #start animation when the start button is clicked ix=0 iy=120/mag ie=0 while abs(ix) <= iy: if (ie < 0): ie = ie + iy + iy -1 iy = iy - 1 ie = ie - ix - ix - 1 ix = ix + 1 pixset(ix,iy); pixset(iy,ix) pixset(-ix,iy); pixset(iy,-ix) pixset(ix,-iy); pixset(-iy,ix) pixset(-ix,-iy); pixset(-iy,-ix) 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("'Bresenham Circle on Graph Paper 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