Automate

Automate

Make your phone or tablet smarter with automation

Get it on Google Play

colorRecode

value colorRecode(color, transform, alpha)

Returns color transcoded according transform, optionally with alpha.

Used for converting between color models, decoding (unpack) a single color value into an array of color components, encoding (pack) an array of color components into a single color value, or any combination thereof.

For consistency, the element in an array of color components are always numbers between 0 and 1, even if they represent degrees such as in Hue, etc..

Transform “stages”, names are case-insensitive:

  • RGBRGB color model, where components represent Red, Green and Blue. Used as first “stage” to specify or decode the initial color into components as/of this model, otherwise for converting to this model. Can be followed by PACK or HEX for encoding into a single color value.
  • HSVHSV color model, where components represent Hue, Saturation and (lightness) Value. Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.
  • PACK — Encode components into a single number. Currently only allowed after a RGB color model, for encoding it into a 32-bit ARGB color number.
  • HEX — Encode components into a single hexadecimal text. Currently only allowed after a RGB color model, for encoding it into a hexadecimal text (i.e. hexEncode) of its 32-bit ARGB color number.

Examples

  • Decode a 32-bit ARGB color number into its components:
    colorRecode(0xFFFF0000, "rgb") returns [1,0,0]
  • Decode and convert a 32-bit ARGB color number into separate HSV components:
    colorRecode(0xFFFF0000, "rgb hsv") returns [0,1,1]
  • Convert and encode HSV components into a 32-bit ARGB color number:
    colorRecode([0,1,1], "hsv rgb pack") returns 0xFFFF0000
  • Encode RGB components, with 50% alpha, into a ARGB hexadecimal text:
    colorRecode([1,0,0], "rgb hex", 0.5) returns "80ff0000"

Parameters

  1. colorarray of color components, or encoded color number or text.
  2. transformtext with space-separated list of one or more transformation “stages”, interpreted from left to right.
  3. alpha — optional alpha (transparency) override [0..1].

Returns

Note! This documentation can also be found in the Help & feedback menu of the app.