Difference between revisions of "Color"
m |
m (→Usage Notes) |
||
Line 29: | Line 29: | ||
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. | 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. | ||
+ | |||
+ | [[Soda]] does not yet have a built-in <c>color</c> module. It does, however, represent colors in the same string format. | ||
== Example == | == Example == |
Revision as of 19:41, 5 August 2021
Color in Mini Micro and Soda is represented in RGB or RGBA hexadecimal format, similar to HTML color codes.
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 /sys/startup.ms
. The 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 [red, geen, blue, alpha]
|
color.fromList(colorList) | convert a list of the above form into a color string |
Usage Notes
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.
Soda does not yet have a built-in color
module. It does, however, represent colors in the same string format.
Example
The following example changes the text color to bright green, using the named color lime
in the color
module.
text.color = color.lime
print "Assigned " + color.lime + ", and text.color is now " + text.color
Output:
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.