# -*- coding: utf-8-sig -*- # NOTE FOR CANOPY USERS: 'turtle' is based on a GUI called 'tkinter' which is different from # what Canopy is based on that's called 'pylab'. Hence, in order to be able to use turtle in # Canopy, you should do the following: # Click on Canopy - Preferences - Python, then uncheck 'Use Pylab'. # Source: http://www.daniweb.com/software-development/python/code/216557/turtle-graphics-python # Official python-turtle documentation: http://docs.python.org/2/library/turtle.html from turtle import * import time speed("slowest") #option 'fastest' will be handy for long iterations tracer(1) # only the nth screen update is shown. Set to 0 to turn tracer off. # The pen/turtle starts at the center (x=0, y=0) of the turtle display area by default. pencolor("green") # While the pen is up, turtle can't draw; this is useful if you want the turtle to # go to a different location. penup() # Have the turtle go to the center of the screen goto(0,0) # put the pen down so the turtle can draw pendown() # Draw a circle with radius = 50 units. # The turtle doesn't draw the circle with its center at (0,0) however; it only draws # a circle that passes through the point (0,0). circle(50) time.sleep(2) # wait for 2 seconds # draw blue 100x100 squares pencolor(0.9,0.3,0.7) #(red,green,blue) triplet # At this point, by default, the turtle is facing east (right) for deg in range(0, 61, 20): right(90 + deg) # turn right by angle = 90 + deg forward(100) # step forward by 100 units while drawing a line right(90) forward(100) right(90) forward(100) right(90) forward(100) time.sleep(1) ps = pensize() # get curent size of pen pensize(ps + 1) # set new size of pen penup() goto(-150,-120) color("red") write("Done!") #IMPORTANT: if you don't do the following, the window might freeze done() #finally close the window to release the console