new ng.Color (Mixed value, [String type = rgb]) vs. 1.1.0 Full+Lite

The ng.Color class adds the ability to create, process and convert colors in JavaScript. It supports the most common formats, which are RGB, HSL and Hexadecimal color codes.

Parameters

Mixed value Required vs. 1.1.0 Full+Lite
The value for the color. This parameter can be either a string or an array.
String: It can be a Hexadecimal value (e.g. FFFFFF for white) Since version 1.1.4, the alpha value can be passed as the last two characters of the string in hexadecimal value (FF for 100% or 00 for 0%). Also, if the string contain rgb(a) or hsl(a), it will be parsed based on those values. The following color names can be used:
  • Aqua = 00FFFF
  • Black = 000000
  • Blue = 0000FF
  • Fuchsia = FF00FF
  • Gray = 808080
  • Green = 008000
  • Lime = 00FF00
  • Maroon = 800000
  • Navy = 000080
  • Olive = 808000
  • Purple = 800080
  • Red = FF0000
  • Silver = C0C0C0
  • Teal = 008080
  • White = FFFFFF
  • Yellow = FFFF00
Array: The value can also be an array for RGB or HSL. If using an HSL array, the type parameter is required and it should be hsl. The array structure for RGB is [RED, GREEN, BLUE], e.g. [255, 0, 0] for red. HSL should be [HUE, SATURATION, LIGHTNESS], e.g. [0, 100, 100] for red. Since version 1.1.4, the alpha value can be passed as the 4th index of the array.
String type (Optional - Default: rgb) vs. 1.1.0 Full+Lite
The type defines the value array and defaults to rgb. If creating a color using an HSL array, set the type to hsl.

Examples

Creating a new ng.Color
Demo:

Methods

Function ng.Color.set_hsl (value) vs. 1.1.0 Full+Lite
This method will set the color value using an HSL array.
Function ng.Color.get_hsl (alpha) vs. 1.1.0 Full+Lite
Gets the HSL color values as an array[HUE, SATURATION, LIGHTNESS], e.g. [0, 100, 100] for red.
Function ng.Color.set_rgb (value) vs. 1.1.0 Full+Lite
Sets the color value using an RGB array.
Function ng.Color.get_rgb (alpha) vs. 1.1.0 Full+Lite
Gets the RGB values as an array [RED, GREEN, BLUE], e.g. [255, 0, 0] for red.
Function ng.Color.set_hex (value) vs. 1.1.0 Full+Lite
Sets the color using a Hexadecimal value.
Function ng.Color.get_hex (alpha) vs. 1.1.0 Full+Lite
Gets the Hexadecimal values (including the # sign) as a string, e.g. #FF0000 for red.
Function ng.Color.invert () vs. 1.1.0 Full+Lite
This method will invert the color (e.g. change white to black).
Function ng.Color.desaturate () vs. 1.1.0 Full+Lite
Convert the color into grayscale.
Function ng.Color.web_safe () vs. 1.1.0 FULL ONLY
This method will change the color into web safe color. Currently this function is not relevent since most modern browsers can render any color correctly.
Function ng.Color.to_query () vs. 1.1.0 Full+Lite
This method will return a query string for the color in a Hexadecimal code.
Function ng.Color.to_json () vs. 1.1.0 Full+Lite
This method will return a JSON string for the color in a Hexadecimal code.
Function ng.Color.mix (mix_clr, percent) vs. 1.1.0 Full+Lite
Mixes the color using a percentage of a new color mix_clr.
Function ng.Color.get_luminance () vs. 1.1.0 Full+Lite
Gets the color luminance.
Function ng.Color.set_alpha (alpha) vs. 1.1.4 Full+Lite
Set the color alpha (opacity) value.
Function ng.Color.get_alpha () vs. 1.1.4 Full+Lite
Get the color alpha (opacity) value.