The leading pound sign (
#) is required, as are the six digits representing the amounts of red, green, and blue in the color. The last two digits, representing alpha, are optional. If not specified, they are assumed to be FF (fully opaque).
color is also the name of a standard module defined in
color module defines the following 20 named colors:
In addition to the above named colors, the
color module defines the following methods:
|Method or Property||Purpose|
|color.rgb(red, green, blue)||return a color string from red, green, and blue values in the range 0-255|
|color.rgba(red, green, blue, alpha)||return a color string from red, green, blue, and alpha values in the range 0-255|
|color.lerp(colorA, colorB, t)||return a color interpolated between colorA and colorB by amount t (0-1)|
|color.toList(colorStr)||convert a color into a list of the form |
|color.fromList(colorList)||convert a list of the above form into a color string|
System functions that return a color from one of the displays include the alpha component, even if it was left implied when the color was drawn or assigned. You must take this into account when comparing colors, for example by adding "FF" to any 7-character color string to extend it to the full 9 characters before comparing.
The following example changes the text color to bright green, using the named color
lime in the
text.color = color.lime print "Assigned " + color.lime + ", and text.color is now " + text.color
Assigned #00FF00, and text.color is now #00FF00FF
Notice that the color string assigned was only 6 digits (7 characters total), but the color string we get back is a full 9 characters long. These two representations of "lime" color are equivalent.