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:

SETPC "GOLD

SETPC 60

SETPC [255 215 0]

SETPC [255 215 0 1]

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: SETPC [255 215 0 0.5]


ALPHA

Reports the first active turtle’s alpha value; no inputs.

Syntax

ALPHA

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.

Examples

ALPHA Result: 1


BACKGROUND

Also: BG

Reports the background color; no inputs.

Syntax

BACKGROUND

Description

BACKGROUND reports a list of RGB values that represents the current background color of the Graphics panel. 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.

Examples

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


BGPATTERN

Reports the background pattern; no inputs.

Syntax

BGPATTERN

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; one input.

Syntax

COLOR color-index
COLOR [red green blue]
COLOR "color-name

Description

COLOR takes takes a color name (which is one of 139 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 138, 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.

Examples

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


COLORINDEX

Coerces a color value to a basic Logo color number; one input.

Syntax

COLORINDEX "color-name
COLORINDEX [red green blue]

Description

COLORINDEX takes a color name (which is one of 139 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.

Examples

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


COLORNAME

Reports the name of a color if possible; one input.

Syntax

COLORNAME number
COLORNAME list

Description

COLORNAME takes a color name (which is one of 139 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.

Examples

COLORNAME [245 222 179] Result: WHEAT


COLORS

Reports a list of available color names; no inputs.

Syntax

COLORS

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 139 Web color names. See also COLOR and COLORNAME.

Examples

COUNT COLORS Result: 139


PATTERN

Reports the turtle’s pattern; no inputs.

Syntax

PATTERN

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.

Examples

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


PENCOLOR

Also: PC

Reports the pen color; no inputs.

Syntax

PENCOLOR

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.

Examples

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


SETALPHA

Sets the default transparency value for colors; one input.

Syntax

SETALPHA alphavalue

Description

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 transparency value set to the turtle’s alpha value. The same happens if you supply a list of three color values without an transparency value.

An alpha value is a value between 0 and 1, where 0 is fully transparent (invisible) and 1 is fully opaque.

Examples

Draw three transparent circles:SETALPHA 0.3 PU SETX -30 PD SETPC “RED (STAMPOVAL 50 50 TRUE) PU SETX 30 PD SETPC “GREEN (STAMPOVAL 50 50 TRUE) PU SETXY [0 50] PD SETPC “BLUE (STAMPOVAL 50 50 TRUE)


SETBG

Sets the background color; one input.

Syntax

SETBG color-number
SETBG "color-name
SETBG [red green blue alpha]
SETBG [red green blue]

Description

SETBG takes a color name (which is one of 139 standard Web color names, see COLORS), a color number between 0 and 138, 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 panel, 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.

Examples

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


SETBGPATTERN

Sets the background pattern; one input.

Syntax

SETBGPATTERN number
SETBGPATTERN list
SETBGPATTERN bitmap-name

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 8x8 bit pattern to be used as the background pattern (note that if the list is shorter, the missing values are treated as the value 0). 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.

To set the fill pattern for turtle drawing operations, use SETPATTERN.

Examples

SETBG “RED ; The bit pattern would be (in binary instead of decimal): ; #B10000001 #B01000010 #B00100100 #B00011000 #B00011000 #B00100100 #B010000010 #B10000001 SETBGPATTERN [129 66 36 24 24 36 66 129]


SETPATTERN

Sets the turtle pattern; one input.

Syntax

SETPATTERN number
SETPATTERN list
SETPATTERN bitmap-name

Description

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

If SETPATTERN is called with a list of eight numbers between 0 and 255, this list is treated as an 8x8 bit pattern to be used as the background pattern (note that if the list is shorter, the missing values are treated as the value 0). If SETPATTERN is called with the name of a bitmap or turtle, the image of that widget 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. So if you, for example, have 16 turtles, pattern numbers 12 to 15 actually refer to the shape of turtles 12 to 15, since these are the turtle’s names.

Also note that you need to set the turtle’s pen color to something else than white to draw patterns 0 to 11.

To set the background pattern for the Graphics panel, use SETBGPATTERN. This command also has an example of a bit pattern.

Examples

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


SETPENCOLOR

Also: SETPC

Sets the pen color; one input.

Syntax

SETPC color-number
SETPC "color-name
SETPC [red green blue alpha]
SETPC [red green blue]

Description

SETPC takes a color name (which is one of 139 standard Web color names, see COLORS), a color number between 0 and 138, 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 number is used, the turtle’s alpha value is used (see SETALPHA).

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

Examples

SETW 3 REPEAT 36 [SETPC PICK COLORS FD 20 LT 10]