Graphics Panel Commands
WRAP BOUNCE FENCE SETBOUNDS BOUNDS
In this section, you will learn about commands to control how the turtle moves in the Graphics panel, or drawing canvas.
If you were to make the Graphics panel smaller than it usually is, you would see very faint grid lines. If you drag a corner of the Graphics panel in any direction, the panel will snap to the grid lines.
If you are curious and want to find out the size of the Graphics panel, you can use the following predefined property. It reports two numbers: the width and height of the panel in pixels. GPROP
stands for Get Property.
PR GPROP "GRAPHICS "DRAWSIZE
384 302
This is the size of the Graphics panel used to create the images on this page. Normally you would have a much larger Graphics panel.
Let’s explore the different drawing modes for the Graphics panel.
WRAP
WRAP
is the how the turtle normally moves. When it reaches the edge of the Graphics Panel, it continues around to the other side of the panel.
The commands used were: DRAW WRAP RT 45 FD 2000
Note that using DRAW
automatically sets the mode to WRAP
.
See the other commands on this page for alternative modes.
» Things to Try
Turn the turtle at different angles and move it forward until it just reaches the edge of the drawing canvas.
Then move it forward a little more. Watch how the turtle wraps around the screen.
Now, use much larger forward (or back) numbers and see how the turtle behaves.
BOUNCE
BOUNCE
makes the turtle bounce off the edges of the drawing canvas instead of wrapping around.
If it is pointing at a heading of 45° when it reaches the edge of the Graphics Panel, it will turn 90° to a heading of 135°. Look at the picture below to see the effect of the BOUNCE
mode. Can you follow the turtle’s journey?
The commands used were: DRAW BOUNCE RT 45 FD 2000
» Things to Try
Experiment with different angles to see how the turtle bounces around the drawing canvas.
Think of how you might use this command in programs you write.
FENCE
FENCE
makes the turtle stop when it reaches the edge of the Graphics panel. It doesn’t wrap around and it doesn’t bounce. The turtle just stops, as if it ran into a fence.
The commands used were: DRAW FENCE RT 45 FD 2000
» Things to Try
Experiment with FENCE
and think of how you might use this command in programs you write.
SETBOUNDS number
(SETBOUNDS width height)
(SETBOUNDS)
SETBOUNDS
sets, or restricts, the drawing area within the Graphics panel.
If you give SETBOUNDS
one number as input, it sets both the width and the height of the drawing area to that size (in pixels).
if you give SETBOUNDS
two numbers as inputs, the first is the width and the second is the height that are set.
if you use (SETBOUNDS)
in parentheses, the boundaries are removed.
In this first example, the commands used were: DRAW SETBOUNDS 100 RT 35 FD 2000
In this second example, the commands used were: DRAW (SETBOUNDS 75 150) RT 35 FD 2000
» Things to Try
Try setting the bounds to different numbers to see how it works. You can get very interesting results.
BOUNDS
If you have used SETBOUNDS
, BOUNDS
reports that information. It gives you a list of two numbers that are the distance from the turtle’s home in the center of the screen to the right or left, and from the top or bottom. These are the maximum distances that the turtle can travel within the Graphics panel.
Here is an example:
SETBOUNDS 200
BOUNDS
Result: [200 200]
The numbers that BOUNDS
reports mean that the turtle could travel 200 steps to the right or left of the center of the screen and 200 to the top or bottom of the Graphics panel.
» Things to Try
The FIRST
and LAST
reporters, which you can learn about in the Taking Things Apart section let you use these numbers with SETX
and SETY
commands. FIRST
reports the first item in a word or list. LAST
reports the last item in a word or list. As you can see, they are quite easy to remember!
For example, you could type SETX FIRST BOUNDS
to move the turtle to the far right of the Graphics panel.
You could type SETY LAST BOUNDS
to move the turtle to the top of the Graphics panel.
Give these and other commands a try.