The turtlegraphics API

 

The turtlegraphics module includes a single class named Turtle. Each Turtle object represents a single window with an invisible pen for drawing in that window. The window uses Cartesian coordinates. When the programmer imports the Turtle class and instantiates it, its window pops up. At that point, the programmer can run various methods with the Turtle object to draw shapes within its window. Multiple Turtle objects and their windows can be active and visible at the same time. This code can be run either interactively within a Python shell or from a Python script. We recommend that the shell or script by launched from a system terminal rather than from IDLE.

Turtle Methods

Turtle() Creates and returns a Turtle object. The turtle's window, which pops up, has a width and height of 200 pixels. The turtle's position is (0, 0), its color is blue, its width is 2 pixels, and its direction is 90 degrees (due north).

Turtle(width, height) Creates and returns a Turtle object. The turtle's window, which pops up, has the specified width and height. The turtle's position is (0, 0), its color is blue, its width is 2 pixels, and its direction is 90 degrees (due north).

getWidth() Returns the width of the turtle's window.

getHeight() Returns the width of the turtle's window.

home() Moves the turtle immediately to position (0, 0) without drawing and sets its direction to 90 degrees (due north).

down() Places the turtle down on the drawing surface, ready to draw on the next move.

up() Raises the turtle above the drawing surface so that it can move without drawing.

move(distance) Moves the given distance in the current direction. If the turtle is down, a line segment is drawn.

move(x, y) Moves to the given position. If the turtle is down, a line segment is drawn.

turn(degrees) Rotates the turtle the given number of degrees from its current direction. A negative amount rotates clockwise and a positive amount rotates counterclockwise.

setDirection(degrees) Sets the turtle's direction to the specified degrees.

setColor(r, g, b) Sets the turtle's color to the given RGB value. These values must range from 0 through 255.

setWidth(size) Sets the turtle's line width to the given size.