Takes a named string, hex string, array of rgb or rgba values,
an object with r, g, b, and a properties, or another Color object
and creates a new Color instance to work from.
| Parameter | Type | Description |
|---|---|---|
| color | Array | String | Object |
See the dojo/_base/Color reference documentation for more information.
Work with a Color instance:
require(["dojo/_base/color"], function(Color){
var c = new Color();
c.setColor([0,0,0]); // black
var hex = c.toHex(); // #000000
});
Work with a node's color:
require(["dojo/_base/color", "dojo/dom-style"], function(Color, domStyle){
var color = domStyle("someNode", "backgroundColor");
var n = new Color(color);
// adjust the color some
n.r *= .5;
console.log(n.toString()); // rgb(128, 255, 255);
});
Dictionary list of all CSS named colors, by name. Values are 3-item arrays with corresponding RG and B values.
| Parameter | Type | Description |
|---|---|---|
| r | undefined | |
| g | undefined | |
| b | undefined | |
| a | undefined |
Blend colors end and start with weight from 0 to 1, 0.5 being a 50/50 blend, can reuse a previously allocated Color object for the result
| Parameter | Type | Description |
|---|---|---|
| start | dojo/_base/Color | |
| end | dojo/_base/Color | |
| weight | Number | |
| obj | dojo/_base/Color |
Optional
|
Builds a Color from a 3 or 4 element array, mapping each
element in sequence to the rgb(a) values of the color.
| Parameter | Type | Description |
|---|---|---|
| a | Array | |
| obj | dojo/_base/Color |
Optional
|
A Color object. If obj is passed, it will be the return value.
require(["dojo/_base/color"], function(Color){
var myColor = new Color().fromArray([237,237,237,0.5]); // grey, 50% alpha
});
Converts a hex string with a '#' prefix to a color object.
Supports 12-bit #rgb shorthand. Optionally accepts a
Color object to update with the parsed value.
| Parameter | Type | Description |
|---|---|---|
| color | String | |
| obj | dojo/_base/Color |
Optional
|
A Color object. If obj is passed, it will be the return value.
require(["dojo/_base/color"], function(Color){
var thing = new Color().fromHex("#ededed"); // grey, longhand
var thing2 = new Color().fromHex("#000"); // black, shorthand
});
get rgb(a) array from css-style color declarations
this function can handle all 4 CSS3 Color Module formats: rgb, rgba, hsl, hsla, including rgb(a) with percentage values.
| Parameter | Type | Description |
|---|---|---|
| color | String | |
| obj | dojo/_base/Color |
Optional
|
Parses str for a color value. Accepts hex, rgb, and rgba
style color values.
Acceptable input values for str may include arrays of any form accepted by dojo.colorFromArray, hex strings such as "#aaaaaa", or rgb or rgba strings such as "rgb(133, 200, 16)" or "rgba(10, 10, 10, 50)"
| Parameter | Type | Description |
|---|---|---|
| str | String | |
| obj | dojo/_base/Color |
Optional
|
A Color object. If obj is passed, it will be the return value.
creates a greyscale color with an optional alpha
| Parameter | Type | Description |
|---|---|---|
| g | Number | |
| a | Number |
Optional
|
Takes a named string, hex string, array of rgb or rgba values,
an object with r, g, b, and a properties, or another Color object
and sets this color instance to that value.
| Parameter | Type | Description |
|---|---|---|
| color | Array | String | Object |
Takes a named string, hex string, array of rgb or rgba values,
an object with r, g, b, and a properties, or another Color object
and sets this color instance to that value.
require(["dojo/_base/color"], function(Color){
var c = new Color(); // no color
c.setColor("#ededed"); // greyish
});
Returns a css color string in rgb(a) representation
| Parameter | Type | Description |
|---|---|---|
| includeAlpha | Boolean |
Optional
|
require(["dojo/_base/color"], function(Color){
var c = new Color("#FFF").toCss();
console.log(c); // rgb('255','255','255')
});
Returns a CSS color string in hexadecimal representation
require(["dojo/_base/color"], function(Color){
console.log(new Color([0,0,0]).toHex()); // #000000
});
Returns 3 component array of rgb values
require(["dojo/_base/color"], function(Color){
var c = new Color("#000000");
console.log(c.toRgb()); // [0,0,0]
});
Returns a 4 component array of rgba values from the color represented by this object.