Fleegix.js
Simple. Useful. JavaScript.

Plugins: fleegix.color.convert


Color conversion functions, including:

Download fleegix.color.convert (4KB)

fleegix.color.convert.hex2rgb

Syntax

fleegix.color.convert.hex2rgb(hexString);

Parameters

hexString (String) -- A hex string representing a color (e.g., #f00, #ccccaa).

Description

Takes a string representing a color in hex format, and converts it to RGB format. Returns an array of the three numbers -- output range for the each of the values is 0-255.

Examples

var rgb = fleegix.color.convert.hex2rgb('#99a');

fleegix.color.convert.rgb2hex

Syntax

fleegix.color.convert.rgb2hex(r, g, b);

fleegix.color.convert.rgb2hex(rgbArray);

Parameters

r (Number) -- The red value for the desired color. Input range is 0-255.

g (Number) -- The green value for the desired color. Input range is 0-255.

b (Number) -- The blue value for the desired color. Input range is 0-255.

rgbArray (Array) -- An array of three numbers representing r, g, b in a range of 0-255.

Description

Takes a three numbers representing a color in RGB format, and converts it to a string in hex format.

Examples

var hex = fleegix.color.convert.rgb2hex(153, 153, 170);
var rgb = [110, 110, 110];
var hex = fleegix.color.convert.rgb2hex(rgb);

fleegix.color.convert.hsv2rgb

Syntax

fleegix.color.convert.hsv2rgb(h, s ,v);

fleegix.color.convert.hsv2rgb(hsvArray);

Parameters

h (Number) -- The hue value for the desired color. Input range is 0-360.

s (Number) -- The saturation value for the desired color. Input range is 0-100.

v (Number) -- The hue value for the desired color. Input range is 0-100.

hsvArray (Array) -- An array of three numbers representing h, s, v in the ranges described above.

Description

Takes three values for hue, saturation, and value representing a color, and converts them to RGB format. Returns an array of the three numbers -- output range for the each of the values is 0-255.

Examples

var rgb = fleegix.color.convert.hsv2rgb(310, 20, 20);
var hsv = [300, 12, 12];
var rgb = fleegix.color.convert.hsv2rgb(rgb);

fleegix.color.convert.rgb2hsv

Syntax

fleegix.color.convert.rgb2hsv(r, g, b);

fleegix.color.convert.rgb2hsv(rgbArray);

Parameters

r (Number) -- The red value for the desired color. Input range is 0-255.

g (Number) -- The green value for the desired color. Input range is 0-255.

b (Number) -- The blue value for the desired color. Input range is 0-255.

rgbArray (Array) -- An array of three numbers representing r, g, b in a range of 0-255.

Description

Takes a three numbers representing a color in RGB format, and converts them to HSV format. Returns an array of the three numbers -- output ranges are [0-360, 0-100, 0-100] for [h, s, v].

Examples

var rgb = fleegix.color.convert.hsv2rgb(310, 20, 20);
var hsv = [300, 12, 12];
var rgb = fleegix.color.convert.hsv2rgb(rgb);