Patterns
SETPATTERN PATTERN SETBGPATTERN BGPATTERN
In this section, you will learn about commands to use patterns, both for the turtle’s pen and the background of the drawing canvas.
SETPATTERN number
SETPATTERN list
SETPATTERN turtle
Use SETPATTERN
to create a pattern of dots to fill a circle or square.
Use STAMPOVAL
or STAMPRECT
with a third input of TRUE
. See the Circles, Squares, Arcs commands.
Don’t use the FILL
command.
Tere are three types of inputs to SETPATTERN
.
SETPATTERN number
You can use one of 11 ready-made patterns. They look like this:
Try this set of instructions to see how it works:
SETPATTERN 8
(STAMPOVAL 100 100 TRUE)
To clear a pattern, use SETPATTERN 0
.
SETPATTERN list
You can also create your own pattern. Give SETPATTERN
a list of 8 numbers between 0 and 255.
For example:
SETPATTERN [200 3 100 13 200 203 100 103]
(STAMPRECT 75 75 TRUE)
SETPATTERN turtle
This use of SETPATTERN
is a bit trickier. However, you can follow this example to see how to create a pattern for a square or circle using a turtle shape.
- Set a number of turtles that is greater than 11 (the highest pattern number):
SETTURTLES 15
- Hide Turtle 0 with
HT
. - Set the active turtle to 12 using
TELL 12
. - Show the turtle with
ST
. - Put its pen down with
PD
. - Open the Toolbox window and find a shape you like. We’ll use the Turtle in Animals.
- Drag the shape onto Turtle 12. It now appears as the turtle.
- Set the pattern to the shape of Turtle 12, using this instruction:
SETPATTERN 12
. - Use
STAMPOVAL
orSTAMPRECT
to create a shape and use the third option to fill it, like this:(STAMPOVAL 250 250 TRUE)
Here is what you could create:
» Things to Try
Try various patterns with your circles and squares.
Try the pre-defined patterns, new patterns you create with a list, and ones that use turtle shape.
For more about using more than one turtle, see the Multiple Turtles page.
PATTERN
PATTERN
reports the current pattern.
When you first start Logo and haven’t set a pattern, it reports 0.
If you set a pattern using a number, it reports that number.
If you set a pattern using a list, it reports that list.
If you used a turtle shape, it reports the number of the turtle.
» Things to Try
Experiment with patterns and use PATTERN
to see how the result matches the pattern you have set.
SETBGPATTERN number
SETBGPATTERN list
SETBGPATTERN turtle
Use SETBGPATTERN
in the same way as you use SETPATTERN
, except that the pattern will cover the entire background of your drawing canvas.
There are three types of inputs to SETPATTERN
.
SETBGPATTERN number
You can use one of 11 ready-made patterns. They look like this:
To see a background pattern, you need to change the background color to something other than white. Patterns don’t show up on a white background! However, if you set the background pattern before setting the background color, the pattern will appear.
SETBG "RED
SETBGPATTERN 4
To clear a pattern, use SETBGPATTERN 0
.
SETBGPATTERN list
You can also create your own pattern. Give SETBGPATTERN
a list of 8 numbers between 0 and 255.
This set of instructions sets the background color and pattern to random values.
DRAW SETBG RANDOM 138 SETBGPATTERN (LIST RANDOM 255 RANDOM 255 RANDOM 255 RANDOM 255 RANDOM 255 RANDOM 255 RANDOM 255 RANDOM 255)
Learn more about RANDOM
in the Fun with Math section.
Learn how to use LIST
in the Putting Things Together section.
SETBGPATTERN turtle
This use of SETBGPATTERN
is a bit trickier. However, you can follow this example to see how to create a background pattern using a turtle shape.
- Set a number of turtles that is greater than 11 (the highest pattern number).
SETTURTLES 15
- Hide Turtle 0 with
HT
. - Set the active turtle to 12 using
TELL 12
. - Show the turtle with
ST
. - Open the Toolbox window and find a shape you like. We’ll use the Bee-Bot in Robots.
- Drag the shape onto Turtle 12. It now appears as the turtle.
- Set the background pattern to the shape of Turtle 12, using this instruction:
SETBGPATTERN 12
.
Here is what you could create:
Note that even if you change the size of the turtle you are using for the pattern (using SETTS
), the SETBGPATTERN
uses the original size of the turtle.
» Things to Try
Experiment with various background patterns.
Try the pre-defined patterns, new patterns you create with a list, and ones that use turtle shape.
For more about using more than one turtle, see the Multiple Turtles section.
BGPATTERN
BGPATTERN
reports the current background pattern.
When you first start Logo and haven’t set a background pattern, it reports 0.
If you set a background pattern using a number, it reports that number.
If you set a background pattern using a list, it reports that list.
If you used a turtle shape, it reports the number of the turtle.
» Things to Try
Experiment with background patterns and use BGPATTERN
to see how the result matches the pattern you have set.