Hardware Reference
In-Depth Information
Setting the Pen Colour and Size
You can set the colour of the turtle using
.color
followed by the name of the colour
you wish to use inside brackets:
alex.color(“blue”)
Similarly, you can set the size of the pen by using
.pensize
followed by the number
of pixels you wish to use inside brackets:
alex.pensize(5)
Stamping
You can use
.stamp
to leave an imprint of the turtle cursor on the screen to form a
pattern instead of, or as well as, using a pen line:
alex.stamp()
You will see the stamp in action in Figure 4-15.
Some Super Spirals
You can put together combinations of the Python Turtle code you have learned, in
order to make some interesting shapes. Have a go yourself by typing the following two
sequences into new text editor windows and saving them as
SpiralTurtle1.py
(shown in Figure 4-14) and
SpiralTurtle2.py
(Figure 4-15). You can change the
pensize
and
color
arguments to make your own creations.
The Spiral Turtle
import turtle
alex = turtle.Turtle()
alex.color(“darkgreen”)
alex.pensize(5)
alex.shape(“turtle”)
print (range(5,100,2))
for size in range(5,100,2):
alex.forward(size)
alex.left(25)