Colors
SETPC PENCOLOR SETPEN COLORS SETBG BACKGROUND FILL
In this section, you will learn about commands to use colors, both for the turtle’s pen and the background of the drawing canvas.
SETPC "color-name
SETPC color-number
SETPC [red green blue alpha]
Use SETPC
to set the color of the pen that the turtle draws with.
SETPC
is short for SETPENCOLOR
, and you can type that long command, if you want. It works!
There are three types of inputs to SETPC
.
SETPC “color-name
SETPC "RED
sets the turtle’s pen to red. It also changes the turtle shape to that color.
The COLORS
command (see below) reports all the possible color names.
SETPC color-number
Logo recognizes 138 colors by number.
Just use SETPC 37
, for example.
If you use too large a number, you will see an error message.
The ability to use a number as input to SETPC
is powerful, as you can easily choose a color at random, like this:
SETPC RANDOM 138
for a number from 1 to 138.
To include 0, use this: SETPC (RANDOM 139)-1
For more information on RANDOM
, see the Fun with Math section.
SETPC [red green blue alpha]
This input is a set of RGB numbers and an optional alpha value (more about that below).
(RGB stands for red, green, blue.)
RBG values range from 0 to 255. The value of white is [255 255 255]. The value for black is [0 0 0].
This list gives you a shade of blue. You can experiment with different RGB values.
SETPC [0 38 255]
You can include an optional fourth input for the alpha value. This is a number between 0 and 1 that sets how transparent the color is. That allows you to create pictures like this:
For the Logo code to draw this, see the solutions for the May 2024 Turtle Tuesday challenges.
To reset the turtle to its original color state, use SETPC 0
.
» Things to Try
Try picking a color at random using either color numbers or RGB values.
This page in the Logo manual shows all the Logo colors, with their names, numbers, and RGB values.
PENCOLOR
PC
PENCOLOR
reports the color of the turtle’s pen in the form of a list of 4 numbers: [red green blue alpha].
You may have used a color name or a number to set the color with SETPC
, but the color is always reported in the form of a list.
SETPC "RED
PC
Result: [255 0 0 1]
See also DOTCOLOR
in the Turtle Coordinates section.
» Things to Try
Use SETPC
to set the turtle’s pen to different colors and then use PC
to see the RGB values.
What happens if you use SETPC
with PC
?
You might think that you could write an instruction like this, the way you can use SETWIDTH
and WIDTH
:
SETPC PC + 1
But does it work? No, because PC reports a list of 4 numbers. As you become acquainted with handling lists, perhaps you can come up with a way to change the color using SETPC
and PC
. (See the sections on Putting Things Together and Taking Things Apart.)
SETPEN [penstate pencolor]
Use SETPEN
to change the state of the turtle’s pen and the pen color in one command.
SETPEN
takes two inputs, described below.
The first item in the list, the pen’s state, can be PENUP
, PENDOWN
, PENERASE
, or PENREVERSE
.
Note that you cannot use abbreviations for these commands. You need to use the full word.
The second item sets the color using one of the methods described in SETPC
:
- a number from 0 to 138, as in
SETPEN [PENUP 3]
- a color name (without the quotes before the name), as in
SETPEN [PENDOWN RED]
- a list of three RGB values, which specifies the pen color, as in
SETPEN [PENREVERSE [0 128 0 1]
.
You may remember that PEN
reports the turtle’s pen state and PENCOLOR
reports the turtle’s pen color.
» Things to Try
Try using SETPEN
with different combinations of pen states and colors.
COLORS
COLORS
is a reporter that tells you the names of all the colors Logo knows about: all 139 of them!
» Things to Try
Just type COLORS
to see the list.
SETBG "color-name
SETBG color-number
SETBG [red green blue alpha]
Use SETBG
to set the background color of the drawing canvas (Graphics panel).
When SETBG
changes the background color, the current drawing isn’t affected. If you have set a background pattern, any background image is visible through the background pattern.
There are three types of inputs to SETBG
.
SETBG “color-name
SETBG "PINK
sets the background color to pink.
The COLORS
command (see above) reports all the possible color names.
SETBG color-number
Logo recognizes 139 colors by number.
Just use SETBG 37
, for example.
If you use too large a number, you will see an error message.
The ability to use a number as input to SETBG
is powerful, as you can easily choose a color at random, like this:
SETBG RANDOM 138
for a number from 1 to 138.
To include 0, use this: SETBG (RANDOM 139)-1
For more information on RANDOM
, see the Fun with Math section.
SETBG [red green blue alpha]
This input is a set of RGB numbers and an optional alpha value (more about that below).
RBG values range from 0 to 255. The value of white is [255 255 255]. The value for black is [0 0 0].
This list gives you a shade of blue. You can experiment with different RGB values.
SETBG [0 38 255]
» Things to Try
Try changing the background to different colors, both before and after you have drawn a design.
What happens if part of your design is the same color as the new background color? Try it and see!
(Don’t forget that you can use Undo or click the red Undo button to cancel the last command you gave.)
BACKGROUND
BG
BACKGROUND
reports the color of the background in the form of a list of 4 numbers: [red green blue alpha].
You may have used a color name or a number to set the color with SETBG
, but the color is always reported in the form of a list.
SETBG "RED
BG
Result: [255 0 0 1]
» Things to Try
Use SETBG
to set the turtle’s pen to background colors and then use BG
to see the RGB values.
FILL
FILL
fills an area of the drawing canvas with the current pen color. FILL
stops filling when it reaches a closed border of any other color.
This means that you can fill any shape you draw. Just lift the turtle’s pen with PENUP
, move the turtle inside the shape, put the pen down with PD
, set the pen color you want, and type FILL
.
The pen needs to be down for FILL
to work. If FILL
isn’t working, type PD
.
If you start with an clean drawing canvas, FILL
acts just like SETBG
with the current pen color.
» Things to Try
Try using FILL
in a variety of situations.
If FILL
doesn’t do what you expect, it is because FILL
is actually a very complicated command. You can read all about FILL
here.