Home

# Library goog.color

Function Summary
| `blend(?Array.<number> rgb1, ?Array.<number> rgb2, number factor) ⇒ !Array` Blend two colors together, using the specified factor to indicate the weight given to the first color
| `colorDiff_(?Array.<number> rgb1, ?Array.<number> rgb2) ⇒ number` Calculate color difference between two colors. Helper method for goog.color.highContrast()
| `darken(?Array.<number> rgb, number factor) ⇒ !Array` Adds black to the specified color, darkening it
| `hexToHsl(string hex) ⇒ !Array` Converts a hex representation of a color to HSL.
| `hexToHsv(string hex) ⇒ !Array` Converts a hex representation of a color to HSV
| `hexToRgb(string hexColor) ⇒ !Array` Converts a hex representation of a color to RGB.
| `hexToRgbStyle(string hexColor) ⇒ string` Converts a hex representation of a color to RGB.
| `highContrast(?Array.<number> prime, ?Array.<(Array|null)> suggestions) ⇒ !Array` 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
| `hslArrayToHex(?Array.<number> hsl) ⇒ string` Converts from an hsl array to a hex string
| `hslArrayToRgb(?Array.<number> hsl) ⇒ !Array` Converts a color from HSL color space to RGB color space.

`hslDistance(?Array.<number> hsl1, ?Array.<number> hsl2) ⇒ 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

| `hslToHex(number h, number s, number l) ⇒ string` Converts from h,s,l values to a hex string
| `hslToRgb(number h, number s, number l) ⇒ !Array` Converts a color from HSL color space to RGB color space. Modified from {@link http://www.easyrgb.com/math.html}
| `hsvArrayToHex(?Array hsv) ⇒ string` Converts from an HSV array to a hex string
| `hsvArrayToRgb(?Array.<number> hsv) ⇒ !Array` Converts an HSV triplet to an RGB array
| `hsvToHex(number h, number s, number v) ⇒ string` Converts from h,s,v values to a hex string
| `hsvToRgb(number h, number s, number brightness) ⇒ !Array` Converts an HSV triplet to an RGB array. V is brightness because b is reserved for blue in RGB.
| `hueToRgb_(number v1, number v2, number vH) ⇒ number` Helper for hslToRgb.
| `isNormalizedHexColor_(string str) ⇒ boolean` Checks if a string is a normalized hex color. We expect strings of the format #RRGGBB (ex: #1b3d5f) using only lowercase letters.
| `isValidColor(string str) ⇒ boolean` Determines if the given string can be parsed as a color. {@see goog.color.parse}.
| `isValidHexColor_(string 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).
| `isValidRgbColor_(string str) ⇒ !Array` 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].
| `lighten(?Array.<number> rgb, number factor) ⇒ !Array` Adds white to the specified color, lightening it
| `normalizeHex(string hexColor) ⇒ string` Normalize an hex representation of a color
| `parse(string str) ⇒ ?Object` Parses a color out of a string.
| `parseRgb(string str) ⇒ !Array` Parses red, green, blue components out of a valid rgb color string.
| `prependHashIfNecessaryHelper(string str) ⇒ string` Takes a string a prepends a '#' sign if one doesn't exist. Small helper method for use by goog.color and friends.
| `prependZeroIfNecessaryHelper(string 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.
| `rgbArrayToHex(?Array.<number> rgb) ⇒ string` Converts a color from RGB to hex representation.
| `rgbArrayToHsl(?Array.<number> rgb) ⇒ !Array` Converts a color from RGB color space to HSL color space.
| `rgbArrayToHsv(?Array.<number> rgb) ⇒ !Array` Converts from r,g,b values to an array of HSV values
| `rgbStyle_(?Array.<number> rgb) ⇒ string` Takes an array of [r, g, b] and converts it into a string appropriate for CSS styles.
| `rgbToHex(number r, number g, number b) ⇒ string` Converts a color from RGB to hex representation.
| `rgbToHsl(number r, number g, number b) ⇒ !Array` Converts a color from RGB color space to HSL color space. Modified from {@link http://en.wikipedia.org/wiki/HLS_color_space}.
| `rgbToHsv(number red, number green, number blue) ⇒ !Array` Converts from RGB values to an array of HSV values.
| `yiqBrightnessDiff_(?Array.<number> rgb1, ?Array.<number> rgb2) ⇒ number` Calculate difference in brightness of two colors. Helper method for goog.color.highContrast()
| `yiqBrightness_(?Array.<number> 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()