Show:

CGSGColor Class

Module: Util

Some utils methods extending the Array prototype

Methods

_toHex
(
  • n
)
String private
Parameters:
  • n String

    String or Number representation of a number between 0 and 255

Returns:
String: Example "A6"
darkenHex
(
  • hex
  • factor
)
String
Parameters:
  • hex String

    Hexadecimal value of a color (with or without the started '#'

  • factor Number

    If >0 : lighten. If <0 : darken

Returns:
darkenRGB
(
  • r
  • g
  • b
  • factor
)
Object
Parameters:
  • r Number

    Red value between 0 and 255

  • g Number

    Green value between 0 and 255

  • b Number

    Blue value between 0 and 255

  • factor Number

    If >0 : lighten. If <0 : darken

Returns:
Object: An {r, g, b} object
hex2rgb
(
  • hex
)
Object static

Convert an hexadecimal code for color to R, G and B

Parameters:
  • hex String

    an hexadecimal code, with or without the starting sharp (#)

Returns:
Object: an object encapsulating r, g and b values (from 0 to 255)
hsl2rgb
(
  • h
  • s
  • l
)
Object

HSL to RGB converter. Adapted from http://en.wikipedia.org/wiki/HSLcolorspace

Parameters:
Returns:
Object: A {r, g, b} object
hsv2rgb
(
  • h
  • s
  • v
)
Object

HSV to RGB converter. Adapted from http://en.wikipedia.org/wiki/HSVcolorspace

Parameters:
Returns:
Object: A {r, g, b} object
lerp
(
  • colorFrom
  • colorTo
  • weight
)
String static

Linear interpolation between 2 colors

Parameters:
Returns:
String: a heh value for the interpolated color
multiplyComponent
(
  • c
  • factor
)
Number
Parameters:
Returns:
Number: The multiplied value, between 0 and 255
rgb2hex
(
  • r
  • g
  • b
)
String static

Convert R, G and B value to an hexadecimal code

Parameters:
  • r String

    red value. from 0 to 255.

  • g String

    green value. from 0 to 255.

  • b String

    blue value. from 0 to 255.

Returns:
String: an hexadecimal value for the color, starting with a sharp (#)
rgb2hsl
(
  • r
  • g
  • b
)
Object

RGB to HSL converter. Adapted from http://en.wikipedia.org/wiki/HSLcolorspace

Parameters:
Returns:
rgb2hsv
(
  • r
  • g
  • b
)
Object

RGB to HSV converter. Adapted from http://en.wikipedia.org/wiki/HSVcolorspace

Parameters:
Returns:
Object: An {h, s, v} object