Sunday, April 25, 2004

What have I been doing?

I downloaded python which includes a module called turtle. Many years ago I had an ADAM computer and one of the two programs that I had for it was Logo Turtle! Playing with this module really brought back some memories. I have a couple of scripts I wrote that I would like to share. Both are simple circle drawing. First head over to www.python.org and get your free copy of Python.

After you install it create this file.

#file pdtTurtle.py
from Tkinter import *
import turtle

def DrawCircles(radius, turn):
    repeat = 360 / turn
    for i in range(repeat):
            turtle.circle(radius)
            turtle.left(turn)		
    turtle.up()
    turtle.forward(radius * 4)
    turtle.down()

class TurtlePower(Frame):

	def reset(self):
		turtle.reset()
		turtle.up()
		turtle.goto(-400,0)
		turtle.down()

	def say_hi(self):
		turtle.tracer(1)
		for x in range(3):
        		DrawCircles(100, (x+1) * 10)

	def createWidgets(self):
		self.QUIT = Button(self)
		self.QUIT["text"] = "QUIT"
		self.QUIT["fg"]   = "red"
		self.QUIT["command"] =  self.quit
		self.QUIT.pack({"side": "left"})

		self.RESET = Button(self)
		self.RESET["text"] = "reset"
		self.RESET["fg"]   = "yellow"
		self.RESET["bg"] = "blue"
		self.RESET["command"] =  self.reset
		self.RESET.pack({"side": "left"})

		self.hi_there = Button(self)
		self.hi_there["text"] = "Start",
		self.hi_there["command"] = self.say_hi

		self.hi_there.pack({"side": "left"})

	def __init__(self, master=None):
		turtle.reset()
		Frame.__init__(self, master)
		self.pack()
		self.createWidgets()

app = TurtlePower()
app.mainloop()

Run your script with this command:

python pdtTurtle.py

and click on start. You may want to maximize the screen first. The reset button move the curser to a good starting point, start draws a few circles. Have fun. Next time stop by for the color script.