colors

October 22, 2022

colors

Stability: 2-Stable

There are two ways to represent a color in CloudControl.

One is to use a string "#AARRGGBB" or "#RRGGBB", where AA is the value of Alpha channel (transparency), RR is the value of R channel (red), GG is the value of G channel (green), and BB is The value of the B channel (blue). For example, "#ffffff" means white, and "#7F000000" means semi-transparent black.

The other is to use a hexadecimal "32-bit integer" 0xAARRGGBB to represent a color. For example, 0xFF112233 represents the color "#112233", and 0x11223344 represents the color "#11223344".

You can use colors.toString() to convert a color integer to a string, and use colors.parseColor() to parse a color string into a color integer.

colors.toString(color)

  • color {number} integer RGB color value
  • Return {string}

Returns a string of the color value, the format is "#AARRGGBB".

colors.red(color)

  • color {number} | {string} color value
  • Return {number}

Returns the value of the R channel of the color color, ranging from 0 to 255.

colors.green(color)

  • color {number} | {string} color value
  • Return {number}

Returns the value of the G channel of the color color, ranging from 0 to 255.

colors.blue(color)

  • color {number} | {string} color value
  • Return {number}

Returns the value of the B channel of the color color, ranging from 0 to 255.

colors.alpha(color)

  • color {number} | {string} color value
  • Return {number}

Returns the value of the Alpha channel of color, ranging from 0 to 255.

colors.rgb(red, green, blue)

  • red {number} the value of the R channel of the color
  • blue {number} the value of the G channel of the color
  • green {number} the value of the B channel of the color
  • Return {number}

Returns the integer color value formed by these color channels. The alpha channel will be 255 (opaque).

colors.argb(alpha, red, green, blue)

  • alpha {number} The value of the alpha channel of the color
  • red {number} the value of the R channel of the color
  • green {number} the value of the G channel of the color
  • blue {number} the value of the B channel of the color
  • Return {number}

Returns the integer color value formed by these color channels.

colors.parseColor(colorStr)

  • colorStr {string} A string representing the color, such as "#112233"
  • Return {number}

Returns the integer value of the color.

colors.isSimilar(color2, color2[, threshold, algorithm])

  • color1 {number} | {string} color value 1
  • color1 {number} | {string} color value 2
  • threshold {number} The critical value of color similarity, the default is 4. The value range is 0~255. The larger the value, the smaller the degree of similarity allowed. If the value is 0, the function will return true only when the two colors are equal.
  • algorithm {string} Color matching algorithm, the default is "diff", including:
    • "diff": Difference matching. Matches when the sum of the absolute values ​​of the R, G, and B differences of a given color is less than the threshold.
    • "rgb": rgb Euler distance similarity. Match when the rgb Euler distance with the given color color is less than or equal to the threshold.
    • "rgb+": Weighted rgb Euler distance matching (LAB Delta Eopen in new window).
    • "hs": hs Euler distance matching. hs is the hue value in HSV space.
  • Return {Boolean}

Returns whether the two colors are similar.

colors.equals(color1, color2)

  • color1 {number} | {string} color value 1
  • color1 {number} | {string} color value 2
  • Return {Boolean}

Returns whether the two colors are equal. *Note that this function will ignore the value of the Alpha channel for comparison.

log(colors.equals("#112233", "#112234"));
log(colors.equals(0xFF112233, 0xFF223344));

colors.BLACK

Black, color value #FF000000

colors.DKGRAY

Dark gray, color value #FF444444

colors.GRAY

Gray, color value #FF888888

colors.LTGRAY

Light gray, color value #FFCCCCCC

colors.WHITE

White, color value #FFFFFFFF

colors.RED

Red, color value #FFFF0000

colors.GREEN

Green, color value #FF00FF00

colors.BLUE

Blue, color value #FF0000FF

colors.YELLOW

Yellow, color value #FFFFFF00

colors.CYAN

Cyan, color value #FF00FFFF

colors.MAGENTA

Magenta, color value #FFFF00FF

colors.TRANSPARENT

Transparent, color value #00000000

Last update:
Contributors: Bruce