color

Classes


Public Protected Private

Global Functions

goog.color.blend(rgb1rgb2factor) !goog.color.Rgb
Blend two colors together, using the specified factor to indicate the weight given to the first color
Arguments:
rgb1 : goog.color.Rgb
First color represented in rgb.
rgb2 : goog.color.Rgb
Second color represented in rgb.
factor : number
The weight to be given to rgb1 over rgb2. Values should be in the range [0, 1]. If less than 0, factor will be set to 0. If greater than 1, factor will be set to 1.
Returns: !goog.color.Rgb  Combined color represented in rgb.
code »
goog.color.colorDiff_(rgb1rgb2) number
Calculate color difference between two colors. Helper method for goog.color.highContrast()
Arguments:
rgb1 : goog.color.Rgb
Color represented by a rgb array.
rgb2 : goog.color.Rgb
Color represented by a rgb array.
Returns: number  Color difference.
code »
goog.color.darken(rgbfactor) !goog.color.Rgb
Adds black to the specified color, darkening it
Arguments:
rgb : goog.color.Rgb
rgb representation of the color.
factor : number
Number in the range [0, 1]. 0 will do nothing, while 1 will return black. If less than 0, factor will be set to 0. If greater than 1, factor will be set to 1.
Returns: !goog.color.Rgb  Combined rgb color.
code »
goog.color.hexToHsl(hex) !goog.color.Hsv
Converts a hex representation of a color to HSL.
Arguments:
hex : string
Color to convert.
Returns: !goog.color.Hsv  hsv representation of the color.
code »
goog.color.hexToHsv(hex) !goog.color.Hsv
Converts a hex representation of a color to HSV
Arguments:
hex : string
Color to convert.
Returns: !goog.color.Hsv  hsv representation of the color.
code »
goog.color.hexToRgb(hexColor) !goog.color.Rgb
Converts a hex representation of a color to RGB.
Arguments:
hexColor : string
Color to convert.
Returns: !goog.color.Rgb  rgb representation of the color.
code »
goog.color.hexToRgbStyle(hexColor) string
Converts a hex representation of a color to RGB.
Arguments:
hexColor : string
Color to convert.
Returns: string  string of the form 'rgb(R,G,B)' which can be used in styles.
code »
goog.color.highContrast(primesuggestions) !goog.color.Rgb
Find the "best" (highest-contrast) of the suggested colors for the prime color. Uses W3C formula for judging readability and visual accessibility: http://www.w3.org/TR/AERT#color-contrast
Arguments:
prime : goog.color.Rgb
Color represented as a rgb array.
suggestions : Array.<goog.color.Rgb>
Array of colors, each representing a rgb array.
Returns: !goog.color.Rgb  Highest-contrast color represented by an array..
code »
goog.color.hslArrayToHex(hsl) string
Converts from an hsl array to a hex string
Arguments:
hsl : goog.color.Hsl
hsl representation of the color.
Returns: string  hex representation of the color.
code »
goog.color.hslArrayToRgb(hsl) !goog.color.Rgb
Converts a color from HSL color space to RGB color space.
Arguments:
hsl : goog.color.Hsl
hsl representation of the color.
Returns: !goog.color.Rgb  rgb representation of the color.
code »
goog.color.hslDistance(hsl1hsl2) number
Calculates the Euclidean distance between two color vectors on an HSL sphere. A demo of the sphere can be found at: http://en.wikipedia.org/wiki/HSL_color_space In short, a vector for color (H, S, L) in this system can be expressed as (S*L'*cos(2*PI*H), S*L'*sin(2*PI*H), L), where L' = abs(L - 0.5), and we simply calculate the 1-2 distance using these coordinates
Arguments:
hsl1 : goog.color.Hsl
First color in hsl representation.
hsl2 : goog.color.Hsl
Second color in hsl representation.
Returns: number  Distance between the two colors, in the range [0, 1].
code »
goog.color.hslToHex(hsl) string
Converts from h,s,l values to a hex string
Arguments:
h : number
Hue, in [0, 360].
s : number
Saturation, in [0, 1].
l : number
Luminosity, in [0, 1].
Returns: string  hex representation of the color.
code »
goog.color.hslToRgb(hsl) !goog.color.Rgb
Converts a color from HSL color space to RGB color space. Modified from http://www.easyrgb.com/math.html
Arguments:
h : number
Hue, in [0, 360].
s : number
Saturation, in [0, 1].
l : number
Luminosity, in [0, 1].
Returns: !goog.color.Rgb  rgb representation of the color.
code »
goog.color.hsvArrayToHex(hsv) string
Converts from an HSV array to a hex string
Arguments:
hsv : goog.color.Hsv
hsv representation of the color.
Returns: string  hex representation of the color.
code »
goog.color.hsvArrayToRgb(hsv) !goog.color.Rgb
Converts an HSV triplet to an RGB array.
Arguments:
hsv : goog.color.Hsv
hsv representation of the color.
Returns: !goog.color.Rgb  rgb representation of the color.
code »
goog.color.hsvToHex(hsv) string
Converts from h,s,v values to a hex string
Arguments:
h : number
Hue, in [0, 360].
s : number
Saturation, in [0, 1].
v : number
Value, in [0, 255].
Returns: string  hex representation of the color.
code »
goog.color.hsvToRgb(hsbrightness) !goog.color.Rgb
Converts an HSV triplet to an RGB array. V is brightness because b is reserved for blue in RGB.
Arguments:
h : number
Hue value in [0, 360].
s : number
Saturation value in [0, 1].
brightness : number
brightness in [0, 255].
Returns: !goog.color.Rgb  rgb representation of the color.
code »
goog.color.hueToRgb_(v1v2vH) number
Helper for hslToRgb.
Arguments:
v1 : number
Helper variable 1.
v2 : number
Helper variable 2.
vH : number
Helper variable 3.
Returns: number  Appropriate RGB value, given the above.
code »
goog.color.isNormalizedHexColor_(str) boolean
Checks if a string is a normalized hex color. We expect strings of the format #RRGGBB (ex: #1b3d5f) using only lowercase letters.
Arguments:
str : string
String to check.
Returns: boolean  Whether the string is a normalized hex color.
code »
goog.color.isValidColor(str) boolean
Determines if the given string can be parsed as a color. .
Arguments:
str : string
Potential color string.
Returns: boolean  True if str is in a format that can be parsed to a color.
code »
goog.color.isValidHexColor_(str) boolean
Checks if a string is a valid hex color. We expect strings of the format #RRGGBB (ex: #1b3d5f) or #RGB (ex: #3CA == #33CCAA).
Arguments:
str : string
String to check.
Returns: boolean  Whether the string is a valid hex color.
code »
goog.color.isValidRgbColor_(str) !goog.color.Rgb
Checks if a string is a valid rgb color. We expect strings of the format '(r, g, b)', or 'rgb(r, g, b)', where each color component is an int in [0, 255].
Arguments:
str : string
String to check.
Returns: !goog.color.Rgb  the rgb representation of the color if it is a valid color, or the empty array otherwise.
code »
goog.color.lighten(rgbfactor) !goog.color.Rgb
Adds white to the specified color, lightening it
Arguments:
rgb : goog.color.Rgb
rgb representation of the color.
factor : number
Number in the range [0, 1]. 0 will do nothing, while 1 will return white. If less than 0, factor will be set to 0. If greater than 1, factor will be set to 1.
Returns: !goog.color.Rgb  Combined rgb color.
code »
goog.color.normalizeHex(hexColor) string
Normalize an hex representation of a color
Arguments:
hexColor : string
an hex color string.
Returns: string  hex color in the format '#rrggbb' with all lowercase literals.
code »
goog.color.parse(str) {hex: string, type: string
Parses a color out of a string.
Arguments:
str : string
Color in some format.
Returns: {hex: string, type: string  } 'hex' is a string containing a hex representation of the color, 'type' is a string containing the type of color format passed in ('hex', 'rgb', 'named').
code »
goog.color.parseRgb(str) !goog.color.Rgb
Parses red, green, blue components out of a valid rgb color string. Throws Error if the color string is invalid.
Arguments:
str : string
RGB representation of a color. .
Returns: !goog.color.Rgb  rgb representation of the color.
code »
goog.color.prependHashIfNecessaryHelper(str) string
Takes a string a prepends a '#' sign if one doesn't exist. Small helper method for use by goog.color and friends.
Arguments:
str : string
String to check.
Returns: string  The value passed in, prepended with a '#' if it didn't already have one.
code »
goog.color.prependZeroIfNecessaryHelper(hex) string
Takes a hex value and prepends a zero if it's a single digit. Small helper method for use by goog.color and friends.
Arguments:
hex : string
Hex value to prepend if single digit.
Returns: string  hex value prepended with zero if it was single digit, otherwise the same value that was passed in.
code »
goog.color.rgbArrayToHex(rgb) string
Converts a color from RGB to hex representation.
Arguments:
rgb : goog.color.Rgb
rgb representation of the color.
Returns: string  hex representation of the color.
code »
goog.color.rgbArrayToHsl(rgb) !goog.color.Hsl
Converts a color from RGB color space to HSL color space.
Arguments:
rgb : goog.color.Rgb
rgb representation of the color.
Returns: !goog.color.Hsl  hsl representation of the color.
code »
goog.color.rgbArrayToHsv(rgb) !goog.color.Hsv
Converts from an array of RGB values to an array of HSV values.
Arguments:
rgb : goog.color.Rgb
rgb representation of the color.
Returns: !goog.color.Hsv  hsv representation of the color.
code »
goog.color.rgbStyle_(rgb) string
Takes an array of [r, g, b] and converts it into a string appropriate for CSS styles.
Arguments:
rgb : goog.color.Rgb
rgb representation of the color.
Returns: string  string of the form 'rgb(r,g,b)'.
code »
goog.color.rgbToHex(rgb) string
Converts a color from RGB to hex representation.
Arguments:
r : number
Amount of red, int between 0 and 255.
g : number
Amount of green, int between 0 and 255.
b : number
Amount of blue, int between 0 and 255.
Returns: string  hex representation of the color.
code »
goog.color.rgbToHsl(rgb) !goog.color.Hsl
Converts a color from RGB color space to HSL color space. Modified from http://en.wikipedia.org/wiki/HLS_color_space.
Arguments:
r : number
Value of red, in [0, 255].
g : number
Value of green, in [0, 255].
b : number
Value of blue, in [0, 255].
Returns: !goog.color.Hsl  hsl representation of the color.
code »
goog.color.rgbToHsv(redgreenblue) !goog.color.Hsv
Converts from RGB values to an array of HSV values.
Arguments:
red : number
Red value in [0, 255].
green : number
Green value in [0, 255].
blue : number
Blue value in [0, 255].
Returns: !goog.color.Hsv  hsv representation of the color.
code »
goog.color.yiqBrightnessDiff_(rgb1rgb2) number
Calculate difference in brightness of two colors. Helper method for goog.color.highContrast()
Arguments:
rgb1 : goog.color.Rgb
Color represented by a rgb array.
rgb2 : goog.color.Rgb
Color represented by a rgb array.
Returns: number  Brightness difference.
code »
goog.color.yiqBrightness_(rgb) number
Calculate brightness of a color according to YIQ formula (brightness is Y). More info on YIQ here: http://en.wikipedia.org/wiki/YIQ. Helper method for goog.color.highContrast()
Arguments:
rgb : goog.color.Rgb
Color represented by a rgb array.
Returns: number  brightness (Y).
code »

Global Properties

goog.color.Hsl :
HSL color representation. An array containing three elements [h, s, l]: h (hue) must be an integer in [0, 360], cyclic. s (saturation) must be a number in [0, 1]. l (lightness) must be a number in [0, 1].
Code »
goog.color.Hsv :
HSV color representation. An array containing three elements [h, s, v]: h (hue) must be an integer in [0, 360], cyclic. s (saturation) must be a number in [0, 1]. v (value/brightness) must be an integer in [0, 255].
Code »
goog.color.Rgb :
RGB color representation. An array containing three elements [r, g, b], each an integer in [0, 255], representing the red, green, and blue components of the color respectively.
Code »
goog.color.alpha :
No description.
Code »
goog.color.alphaTest :
No description.
Code »
goog.color.hexTripletRe_ :
Regular expression for extracting the digits in a hex color triplet.
Code »
goog.color.names :
A map that contains a lot of colors that are recognised by various browsers. This list is way larger than the minimal one dictated by W3C. The keys of this map are the lowercase "readable" names of the colors, while the values are the "hex" values.
Code »
goog.color.normalizedHexColorRe_ :
Helper for isNormalizedHexColor_.
Code »
goog.color.rgbColorRe_ :
Regular expression for matching and capturing RGB style strings. Helper for isValidRgbColor_.
Code »
goog.color.validHexColorRe_ :
Helper for isValidHexColor_.
Code »

Package color

Package Reference