5.4 ColorUtil

  Download source    View color-coded source

Content of ColorUtil.js:
Color
A simple object to store a color and perform Hex/RGB conversions.


function Color(hex)
Constructs a new Color object to store the color you provide.

Parameters
    String hex - Hex representation of the color, e.g. #FF0000 for pure red
Returns
    Color - A new Color object with the specified color



function getHex()
Returns the current color in hex format.

Returns
    String - the hex color, with a leading #, e.g. #FF0000



function setHex(hex)
Sets the current color in hex format

Parameters
    String hex - the new color, works with or without a leading #



function setRGB(r, g, b)
Sets the color using RGB values (0-255).

Parameters
    byte r - red value
    byte g - green value
    byte b - blue value



function toString()
Returns a string representation of the object

Returns
    String - a string representation of the color as both Hex and RGB.



ColorBlend
This blends between the two Color objects specified by the constructor's input parameters.



function ColorBlend(colorFrom, colorTo)
Constructs a new ColorBlend object to blend from the colorFrom to colorTo, e.g. ColorBlend(#FF0000, #000000) (blending from pure red to black).

Parameters
    Color colorFrom - color to blend from
    Color colorTo - color to blend to

Returns
    ColorBlend - A ColorBlend object with the two colors



function getColor(alpha)
Returns the color mixed by colorForm and colorTo.

Parameters
    double alpha - The blend factor (a real value between 0 and 1)

Returns
    Color - The blended color



function toString()
Returns a string representation of the object

Returns
    String - a string representation of the ColorBlend object



Helper functions

function RGBToHex(r, g, b)
Rectangle with color and size depending on depth (z value).

Parameters
    byte r - red value
    byte g - green value
    byte b - blue value

Returns
    String - A hex representation of the given RGB color



Constants

var HEXVALUES = "0123456789ABCDEF";
A string constant used for decimal-hex-conversion