Announcements of available shared folders


Postby oliver » Fri Dec 24, 2010 3:13 pm

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
Color1.png (17.95 KiB) Viewed 4791 times

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
Color2.png (5.83 KiB) Viewed 4791 times

and tapping toColor.
Color3.png (5.25 KiB) Viewed 4791 times

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
1/x inverts
* alpha-composites

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
?_JS computes a random color in JavaScript
?_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.

Result of running bench
Color4.png (22.17 KiB) Viewed 4791 times
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Return to Downloadable Folders / Shared Data

Who is online

Users browsing this forum: No registered users and 1 guest