Hardware Reference
In-Depth Information
Turtle Graphics Command Quick Reference Table
(continued)
Commands
Description
pen up
Lifts a sprite's pen so it does not draw.
set pen color to x
Sets a pen's colour to your choice.
set pen shade to x
Sets the pen's shade by x amount.
set pen size x
Set's a pen's line thickness to x.
Stamps a sprite's image on to the stage.
stamp
Turtle Module in Python
import turtle Imports the turtle module into Python. Should be at the
start of any Python Turtle program.
Creating and Naming the “turtle”
alex = turtle.Turtle()
Opens the Turtle Graphics window, with an arrow cursor
in the centre, named alex . The arrow cursor represents the
turtle, whose movements will create your drawing.
Move and Draw
forward( x )
Moves the turtle forward by the speciied distance x , in
the direction the turtle is headed.
left( x )
Turns turtle left by x units.
right( x )
Turns turtle right by x units.
stamp()
Stamps a copy of the turtle shape onto the canvas at the
current turtle position.
Drawing State
pendown()
Puts the pen down and draws when it moves.
penup()
Picks the pen up and stops drawing.
pensize( x )
Sets the thickness of the line drawn to x pixels.
Turtle State
shape(“turtle”)
Sets the cursor icon. Possible values for the shape are:
arrow , turtle , circle , square , triangle , classic .
Colour Control
color(“brown”)
Sets pen colour.
Additional Commands
for
for loops are traditionally used when you have a piece of
code that you want to repeat x number of times. Example:
for i in [0,1,2,3,4,]:
for i in range():
A for loop using the range() function that creates a list
containing numbers.
range()
The range() function generates a list of numbers in pro-
gression.
Search WWH ::




Custom Search