dojox/color/_base (version 1.10)

See the dojox/color/_base reference documentation for more information.

Property Summary

Method Summary

  • blend(start,end,weight,obj) 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
  • 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 creates a new Color instance to work from.
  • fromArray(a,obj) Builds a Color from a 3 or 4 element array, mapping each element in sequence to the rgb(a) values of the color.
  • fromCmy(cyan,magenta,yellow) Create a dojox.color.Color from a CMY defined color.
  • fromCmyk(cyan,magenta,yellow,black) Create a dojox.color.Color from a CMYK defined color.
  • fromHex(color,obj) Converts a hex string with a '#' prefix to a color object.
  • fromHsl(hue,saturation,luminosity) Create a dojox.color.Color from an HSL defined color. hue from 0-359 (degrees), saturation and luminosity 0-100.
  • fromHsv(hue,saturation,value) Create a dojox.color.Color from an HSV defined color. hue from 0-359 (degrees), saturation and value 0-100.
  • fromRgb(color,obj) get rgb(a) array from css-style color declarations
  • fromString(str,obj) Parses str for a color value.
  • Palette(base) An object that represents a palette of colors.

Properties

Colorspace
greyscale
Defined by: dojox/color/_base

Methods

blend(start,end,weight,obj)
Defined by dojo/_base/Color

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
Returns:undefined
Color(color)
Defined by dojo/_base/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 creates a new Color instance to work from.

Parameter Type Description
color Array | String | Object

Examples

Example 1

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
});

Example 2

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);
  });
fromArray(a,obj)
Defined by dojo/_base/Color

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
Returns:any | undefined

A Color object. If obj is passed, it will be the return value.

Examples

Example 1

require(["dojo/_base/color"], function(Color){
    var myColor = new Color().fromArray([237,237,237,0.5]); // grey, 50% alpha
});
fromCmy(cyan,magenta,yellow)
Defined by dojox/color/_base

Create a dojox.color.Color from a CMY defined color. All colors should be expressed as 0-100 (percentage)

Parameter Type Description
cyan Object | Array | int
magenta int
yellow int
Returns:instance
fromCmyk(cyan,magenta,yellow,black)
Defined by dojox/color/_base

Create a dojox.color.Color from a CMYK defined color. All colors should be expressed as 0-100 (percentage)

Parameter Type Description
cyan Object | Array | int
magenta int
yellow int
black int
Returns:instance
fromHex(color,obj)
Defined by dojo/_base/Color

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
Returns:any

A Color object. If obj is passed, it will be the return value.

Examples

Example 1

require(["dojo/_base/color"], function(Color){
    var thing = new Color().fromHex("#ededed"); // grey, longhand
    var thing2 = new Color().fromHex("#000"); // black, shorthand
});
fromHsl(hue,saturation,luminosity)
Defined by dojox/color/_base

Create a dojox.color.Color from an HSL defined color. hue from 0-359 (degrees), saturation and luminosity 0-100.

Parameter Type Description
hue Object | Array | int
saturation int
luminosity int
Returns:instance
fromHsv(hue,saturation,value)
Defined by dojox/color/_base

Create a dojox.color.Color from an HSV defined color. hue from 0-359 (degrees), saturation and value 0-100.

Parameter Type Description
hue Object | Array | int
saturation int
value int
Returns:instance | undefined
fromRgb(color,obj)
Defined by dojo/colors

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
Returns:null
fromString(str,obj)
Defined by dojo/_base/Color

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
Returns:any

A Color object. If obj is passed, it will be the return value.

Palette(base)
Defined by dojox/color/Palette

An object that represents a palette of colors.

A Palette is a representation of a set of colors. While the standard number of colors contained in a palette is 5, it can really handle any number of colors.

A palette is useful for the ability to transform all the colors in it using a simple object-based approach. In addition, you can generate palettes using dojox.color.Palette.generate; these generated palettes are based on the palette generators at http://kuler.adobe.com.

Parameter Type Description
base String | Array | dojox.color.Color | dojox.color.Palette
Error in the documentation? Can’t find what you are looking for? Let us know!