An extension featuring a data type that represents colors, and methods to operate on colors.
After installation, you can enter colors by typing a CSS-style color definition on the command-line.
For example, enter #7656B4 to get
The color can optionally have an alpha component, if you add two extra digits, e,g, #7656B480.
You can also create a color (w/ or w/o alpha) by specifying a 3- or 4-element vector, as in
and tapping toColor.
Semi-transparent colors (those with an alpha values less than 1.0 (or 0xff)) display with two swatches: one showing the color without alpha applied, the other how the color looks alpha-composited over white.
The basic operators work with colors.
+ does a saturated add
- does a saturated minus
Various other methods exist:
mix computes the average between two colors
alpha returns the alpha (coverage) channel as a float value
components returns all color components (use toColor to (re-)construct a color from that)
isOpaque returns true if alpha is 100%, otherwise false
The second page in this folder contains various convenience functions:
noVals hides numerical value display on colors
yesVals re-enables it
?_RPL does the same in RPL
nColors constructs an array of a given number of colors
bench constructs a vector of 100 colors and reports the time to do so
red, green, blue are presets for the respective colors
The extension installs the following constants: white, black, transparent. These are usable from any folder.
To access "red" (not a global constant, but defined in this folder) from an RPL program outside this folder, you'd write: Color.Red
You can create colors in this folder and refer to them in the same way.
In line with normal practice you can apply operators on all elements in a vector. For example, you can use "100, nColor" to create a vector of colors and then tap 1/x to invert them all, or "-" to subtract one array of colors from another, etc.