Terrapin Resources

Logo Colors

The color commands assign colors to the background of the Graphics canvas, or the turtle pen. A color is one of three things: A number between 0 and 137 for the 138 Web colors, a color name (which is one of 138 standard Web color names, see COLORS), or a list of four values, one each for Red, Green, and Blue. These three values may vary from 0 to 255.

The fourth value is optional and describes how transparent a color should be. A value of 0 makes the color invisible, and a value of 1 makes it opaque. This value is also referred to as a color’s alpha value.

Color indexes and color names do not have an own alpha value. Instead, their alpha value is set to 1 (fully opaque), unless you use a turtle command. In that case, the turtle’s alpha value (which you set with the SETALPHA command) is returned as the alpha value of a color name or color index. If you use a color name to work with the background, a value of 1 (fully opaque) is used. The same happens if you supply a list of three color values without an alpha value; for commands related to a turtle, the turtle’s alpha value is used; for all other purposes, an alpha value of 1 is used. See the SETALPHA command for a few examples.

Logo color names are the same as the standard Web color names. These color names go back a long way to the first graphic subsystems based on the X11 architecture in 1986. Nowadays, every Web browser understands these color names.

The tables below display the color names along with their color index and the RGB values, which are the intensities of the Red, Green and Blue components of a color, expressed as values between 0 and 255.

The following commands would all set the pen color to Gold:

If you want to use a transparent gold, you can use a four-element list as in this example, with the alpha value set to 0.5:

For a complete list of colors, see this page.

ALPHA

Reports the first active turtle’s alpha value.

Syntax

Description

ALPHA reports the first active turtle’s alpha value. The turtle uses the alpha value to fill in the alpha value for color names, or three-element color lists that do not have an alpha value.

Example

ALPHA Result: 1

BACKGROUND

Also: BG

Reports the background color.

Syntax

Description

BACKGROUND reports a list of RGB values that represents the current background color of the Graphics canvas. The initial background color is a fully transparent white so background images are fully visible.

For an explanation of how background patterns and images play together, see LOADPIC.

Example

MAKE “MY.BG BG SETBG “LIME SETBG :MY.BG

COLOR

Reports the RGB color value for a color name or color index.

Syntax

Description

COLOR reports the color value for the color name or color index that it received as input.

See also COLORNAME and COLORINDEX.

Example

COLOR “GOLD Result: [255 215 0 1]

COLORINDEX

Also: BASECOLOR

Coerces a color value to a basic Logo color number.

Syntax

Description

COLORINDEX takes a color name (which is one of 138 standard Web color names, see COLORS), or a list of up to four values, one each for Red, Green, and Blue, plus an optional alpha value. The color values may vary from 0 to 255, and the alpha value is between 0 and 1. COLORINDEX maps this color to one of the Web colors used by Logo, and reports the number of that color. If Logo cannot match the color, it reports the value -1.

See also COLORNAME and COLOR.

Example

COLORINDEX [255 165 0] Result: 102 COLORINDEX “ORANGE Result: 102

BGPATTERN

Reports the background pattern.

Syntax

Description

BGPATTERN reports a number that represents the current background pattern of the graphics screen. To set the background pattern of the graphics screen, use SETBGPATTERN. To see a list of predefined patterns, see SETPATTERN. Pattern 0 is an all-on pattern. If you set that pattern, SETBG sets solid colors, hiding any background image.

If a list or the name of an object was used as input to SETBGPATTERN, BGPATTERN reports that value.

For an explanation of how background patterns and images play together, see LOADPIC.

COLOR

Reports the color for a name or value if possible.

Syntax

Description

COLOR takes takes a color name (which is one of 138 standard Web color names, see COLORS), or a list of up to four values, one each for Red, Green, and Blue, plus an optional alpha value. The color values may vary from 0 to 255, and the alpha value is between 0 and 1. COLOR attempts to match the input to a table of known color names, ignoring the alpha value. If a match is found, COLOR outputs the corresponding four-element list of color values, with an alpha value of 1. If COLOR cannot match the color, it reports FALSE. If the input is a number between 0 and 137, COLOR reports the color values for the respective standard color as described in SETPC. If the input is a list of color values, COLOR reports that list.

See also COLORNAME and COLORS.

Example

COLOR “SANDYBROWN Result: [244 164 96 1] COLOR 67 Result: [240 230 140 1]

COLORNAME

Reports the name of a color if possible.

Syntax

Description

COLORNAME takes a color name (which is one of 138 standard Web color names, see COLORS), or a list of up to four values, one each for Red, Green, and Blue, plus an optional alpha value. The color values may vary from 0 to 255, and the alpha value is between 0 and 1. COLORNAME attempts to match its input to a known color name, ignoring the alpha value. If Logo cannot match the color, it reports FALSE.

See also COLOR and COLORS.

Example

COLORNAME [245 222 179] Result: WHEAT

COLORS

Reports a list of available color names.

Syntax

Description

COLORS reports a list of available color words that can be used in place of color numbers or lists of RGB values. The names in this list correspond to the standard 138 Web color names. See also COLOR and COLORNAME.

Example

COUNT COLORS Result: 138

PATTERN

Reports the turtle’s pattern.

Syntax

Description

PATTERN reports a number that represents the current fill pattern of the first active turtle. To set the fill pattern of the graphics screen, use SETBGPATTERN. To see a list of predefined fill patterns, see SETPATTERN; this command also lets you set a turtle’s fill pattern.

Example

SETPC 4 SETPATTERN 2 (STAMPRECT 100 100 TRUE) PATTERN Result: 2

PENCOLOR

Also: PC

Reports the pen color.

Syntax

Description

PENCOLOR reports the current pen color of the first active turtle as a four-element list of red, green and blue color values, plus the alpha value. Use SETPC to alter the drawing color for all active turtles.

Example

SETPC “RED FD 50 PC Result: [255 0 0 1]

SETALPHA

Sets the default alpha value for colors.

Syntax

Description

Color names and color indexes do not have an own alpha value. If you use a color name or index together with a turtle command like e.g. SETPC, Logo looks up the color and returns that color with the alpha value set to the turtle’s alpha value. The same happens if you supply a list of three color values without an alpha value.

Example

ALPHA Result: 1 SETPC “RED PC Result: [255 0 0 1] SETALPHA 0.5 SETPC “RED PC Result: [255 0 0 0.5] ; set an even more transparent pen color SETPC [255 0 0 0.3] PC Result: [255 0 0 0.3]

SETBG

Sets the background color.

Syntax

Description

SETBG takes a color name (which is one of 138 standard Web color names, see COLORS), or a list of up to four values, one each for Red, Green, and Blue, plus an optional alpha value. The color values may vary from 0 to 255, and the alpha value is between 0 and 1.

SETBG sets the background color of the Graphics canvas, leaving the current drawing untouched. If a background pattern is set, any background image is visible through the background pattern.

For an explanation of how background patterns and images play together, see LOADPIC.

For a complete list of color names, see COLORS.

Example

MAKE “MY.BG BG SETBG “GOLD SETBG :MY.BG

SETBGPATTERN

Sets the background pattern.

Syntax

Description

SETBGPATTERN takes a number, a list or a bitmap name as input and sets a pattern for the background of the graphics canvas. The BGPATTERN command reports the currently selected background pattern. To see a list of predefined patterns, see SETPATTERN. Pattern 0 is an all-on pattern. If you set that pattern, SETBG sets solid colors, hiding any background image.

Note that you can use the name of a turtle to set the background pattern to a turtle image, but since the turtle have numbers as names, use numbers above 11, because the values 0 to 11 set standard patterns.

For an explanation of how background patterns and images play together, see LOADPIC.

If SETBGPATTERN is called with a list of eight numbers between 0 and 255, this list is treated as an 8×8 bit pattern to be used as the background pattern. If SETBGPATTERN is called with the name of a bitmap or turtle object, the image of that object is used as a pattern. Note that you cannot use the numbers 0 to 11 to refer to turtles, as these values set a predefined pattern.

SETPATTERN

Sets the turtle pattern.

Syntax

Description

SETPATTERN takes a number or list as input and sets a pattern for filling ovals (using STAMPOVAL) and rectangles (using STAMPRECT). The PATTERN command reports the number of the currently selected fill pattern. If the input value is 0, any existing pattern is removed. The predefined fill patterns are:

       
1 2 3 4
5 6 7 8
9 10 11  

If SETPATTERN is called with a list of eight numbers between 0 and 255, this list is treated as an 8×8 bit pattern to be used as the background pattern. If SETPATTERN is called with the name of a bitmap or turtle object, the image of that object is used as a pattern. Note that you cannot use the numbers 0 to 11 to refer to turtles, as these values set a predefined pattern.

Example

SETPC “RED SETPATTERN 2 (STAMPRECT 100 100 TRUE) PATTERN Result: 2

SETPC

Sets the pen color.

Syntax

Description

SETPC takes a color name (which is one of 138 standard Web color names, see COLORS), or a list of up to four values, one each for Red, Green, and Blue, plus an optional alpha value. The color values may vary from 0 to 255, and the alpha value is between 0 and 1. SETPC sets the pen color for all active turtles. If the alpha value is omitted, or a color name or index is used, the turtle’s alpha value is used (see SETALPHA).

To set the background color of the Graphics canvas, use SETBG.