require(["esri/Color"], function(Color) { /* code goes here */ });
Description
(Added at v3.9)
Inherits all attributes from
dojo/_base/Color to provide functions for setting colors.
See also
Samples
Search for
samples that use this class.
Constructors
Constants
named | Dictionary list of all CSS named colors, by name. Values are 3-item arrays with corresponding RG and B values. |
Properties
Methods
blendColors(start, end, weight, obj?) | Color | Blend colors start and end with weight from 0 to 1, 0.5 being a 50/50 blend. |
fromArray(a, obj?) | Color | Builds a Color from a 3 or 4 element array, mapping each element in sequence to the rgb(a) values of the color. |
fromHex(color, obj?) | Color | Converts a hex string with a '#' prefix to a color object. |
fromRgb(color, obj?) | Color | Returns a Color instance from a string of the form "rgb()" or "rgba()". |
fromString(str, obj?) | Color | Parses str for a color value. |
setColor(color) | Color | 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. |
toCss(includeAlpha?) | String | Returns a css color string in rgb(a) representation. |
toHex() | String | Returns a CSS color string in hexadecimal representation. |
toRgb() | Number[] | Returns a 3 component array of rgb values. |
toRgba() | Number[] | Returns a 4 component array of rgba values. |
Constructor Details
Creates a new Color object.
Parameters:
<String | Number[] | Object > color |
Optional |
A named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color object.
- Named string:
new Color("blue")
- Hex string:
new Color("#C0C0C0")
- R,G,B:
new Color([255,0,0])
- R,G,B,A. The "A" value represents transparency where 0.0 is fully transparent and 1.0 has no transparency:
new Color([255,0,0,0.25])
|
Property Details
The alpha value.
Known values: 0.0-1.0
The blue value.
Known values: 0-255
The green value.
Known values: 0-255
The red value.
Known values: 0-255
Method Details
Blend colors start and end with weight from 0 to 1, 0.5 being a 50/50 blend. Optionally accepts a Color object to update and return instead of creating a new object.
Note: This is a static method.
Parameters:
<Color > start |
Required |
The start color. |
<Color > end |
Required |
The end color. |
<Number > weight |
Required |
The weight value. |
<Color > obj |
Optional |
A previously allocated Color object to reuse for the result. |
Sample:
var startColor = new Color("#0000FF");
var endColor = new Color("#CA0013");
var blendedColor = Color.blendColors(startColor, endColor, 0.5);
Builds a Color from a 3 or 4 element array, mapping each element in sequence to the rgb(a) values of the color. Optionally accepts a Color object to update with the color value and return instead of creating a new object.
Note: This is a static method.
Parameters:
<Number[] > a |
Required |
The input array. |
<Color > obj |
Optional |
A previously allocated Color object to reuse for the result. |
Sample:
var redColor = Color.fromArray([201, 0, 19]);
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 and return instead of creating a new object.
Note: This is a static method.
Parameters:
<String > color |
Required |
The input color. |
<Color > obj |
Optional |
A previously allocated Color object to reuse for the result. |
Sample:
var redColor = Color.fromHex("#CA0013");
Returns a Color instance from a string of the form "rgb()" or "rgba()". Optionally accepts a Color object to update with the parsed value and return instead of creating a new object.
Note: This is a static method.
Parameters:
<String > color |
Required |
The input color. |
<Color > obj |
Optional |
A previously allocated Color object to reuse for the result. |
Sample:
var redColor = Color.fromRgb("rgb(202,0,19)");
Parses str for a color value. Accepts hex, rgb, and rgba style color values. Optionally accepts a Color object to update with the parsed value and return instead of creating a new object.
Note: This is a static method.
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)".
Parameters:
<String > str |
Required |
The input value. |
<Color > obj |
Optional |
A previously allocated Color object to reuse for the result. |
Sample:
var redColor = Color.fromString("rgb(202,0,19)");
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.
Returns a css color string in rgb(a) representation.
Parameters:
<Boolean > includeAlpha |
Optional |
If true, the alpha value will be included in the result. |
Returns a CSS color string in hexadecimal representation.
Returns a 3 component array of rgb values.
Returns a 4 component array of rgba values.