Class: Color

bp.ui. Color

Constructor

new Color(data)

A simple class for calculating, formatting, and parsing color values.
Parameters:
Name Type Description
data object | string Color configuration parameters. If an object, accepts see below for configuration options. If a string, calls Color.fromString() on the value and returns the result.
Properties
Name Type Description
red number Red value (0-255).
green number Green value (0-255).
blue number Blue value (0-255).
alpha number Alpha value (0-255).

Methods

(static) fromString(color) → {bp.ui.Color}

Creates a color object from a string.
Parameters:
Name Type Description
color string The color string to parse.
Returns:
A new color object.
Type
bp.ui.Color
Examples
var color = bp.ui.Color.fromString('#006637');
var color = bp.ui.Color.fromString('rgba(255, 255, 255, 0.5)');

clone() → {bp.ui.Color}

Creates and returns a clone of the current color.
Returns:
The cloned color.
Type
bp.ui.Color

makeForeground() → {bp.ui.Color}

Returns a new color, either black or white, depending on the luminosity of the current color.
Returns:
A new color.
Type
bp.ui.Color

toGrayscale() → {bp.ui.Color}

Returns a grayscale version of the current color.
Returns:
A new (grayscale) color object
Type
bp.ui.Color

toString(hexopt)

Prints the color as a string.
Parameters:
Name Type Attributes Default Description
hex boolean <optional>
false If true, prints as a hex value instead of rgb(x, y, z).
Example
var color = new bp.ui.Color({red: 0, green: 17, blue: 200});
color.toString();  // => 'rgb(0, 17, 200)'
color.toString(true);  // => '#0011c8'