Difference between revisions of "Color"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "Color in Mini Micro is represented in RGB or RGBA hexadecimal format, similar to [https://htmlcolorcodes.com/ HTML color codes]. frameless The l...")
 
(Add Farmtronics category)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Color in [[Mini Micro]] is represented in RGB or RGBA hexadecimal format, similar to [https://htmlcolorcodes.com/ HTML color codes].
+
Color in [[Mini Micro]], [[Farmtronics]], and [[Soda]] is represented in RGB or RGBA hexadecimal format, similar to [https://htmlcolorcodes.com/ HTML color codes].
  
 
[[File:ColorString.png|frameless]]
 
[[File:ColorString.png|frameless]]
Line 21: Line 21:
 
| [[color.lerp]](''colorA'', ''colorB'', ''t'') || return a color interpolated between ''colorA'' and ''colorB'' by amount ''t'' (0-1)
 
| [[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 <c>[red, geen, blue, alpha]</c>
+
| [[color.toList]](''colorStr'') || convert a color into a list of the form <c>[red, green, blue, alpha]</c>
 
|-
 
|-
 
| [[color.fromList]](''colorList'') || convert a list of the above form into a color string
 
| [[color.fromList]](''colorList'') || convert a list of the above form into a color string
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 ==
Line 44: Line 46:
  
 
[[Category:Mini Micro]]
 
[[Category:Mini Micro]]
 +
[[Category:Soda]]
 +
[[Category:Farmtronics]]

Latest revision as of 23:29, 14 November 2022

Color in Mini Micro, Farmtronics, and Soda is represented in RGB or RGBA hexadecimal format, similar to HTML color codes.

ColorString.png

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:

ColorTable.png

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, green, 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.