ludo.color.Color

ludo.color.


new ludo.color.Color()

A class with a lot of color conversion functions.

With this class, you can convert between RGB and HSV, darken and brighten colors,
increase and decrease saturation and brightness of a color etc.

Source:
Example
var util = new ludo.color.Color();
var rgbCode = '#669900';
var rgbObject = util.rgbObject(rgbCode);

Methods


brighten(color, percent) → {String}

Returns a brighter color.

Parameters:
Name Type Description
color String | Object
percent number
Source:
Returns:
Type
String
Example
var util = new ludo.color.Color();
var color = '#669900';
var brighterColor = util.brighten(color, 10);
console.log(brighterColor); // outputs #76A811;
color = '#AAAAAA';
brighterColor = util.brighten(color, 10);
console.log(brighterColor); // outputs #BBBBBB;

darken(color, percent) → {String}

Brightens a color

Parameters:
Name Type Description
color
percent
Source:
Returns:
Type
String
Example
var c = new ludo.color.Color();
     var color = '#BBBBBB';
     var darker = c.darken(color, 10);
     console.log(darker); // outputs #A8A8A8

hsvToRGB(h, s, v) → {Object}

Converts HSV(Hue, Saturation, Brightness) to RGB(red, green, blue).

Parameters:
Name Type Description
h
s
v
Source:
Returns:
Type
Object
Example
var colorUtil = new ludo.color.Color();
var hue = 300;
var saturation = 40;
var brightness = 90;
var rgb = colorUtil.hsvToRGB(hue, saturation, brightness);
 // returns { r: 229, g: 138, b: 229 }

hsvToRGBCode(h, s, v) → {String}

Converts Hue,Saturation,Brightness to RGB Code

Parameters:
Name Type Description
h
s
v
Source:
Returns:
Type
String
Example
var c = new ludo.color.Color();
var color = c.hsvToRGBCode(200,40,60);
console.log(color);

offsetBrightness(color, offset) → {String}

Return rgb code after hue has been adjusted by a number of degrees

Parameters:
Name Type Description
color
offset
Source:
Returns:
Type
String
Example
var c = new ludo.color.Color();
var color = '#FF0000'; // Bright red with full brightness and saturation
color = c.offsetBrightness(color, -10); // 10 degrees darker
console.log(color); // outputs #E60000

offsetHue(color, offset) → {String}

Return rgb code after hue has been adjusted by a number of degrees

Parameters:
Name Type Description
color
offset
Source:
Returns:
Type
String
Example
var c = new ludo.color.Color();
var color = '#FF0000'; // red
color = c.offsetHue(color, 10);
console.log(color); // Outputs #FF2A00

offsetSaturation(color, offset) → {String}

Return rgb code after saturation(color intensity) has been adjusted. Saturation can be 0-100(no saturation to full saturation)

Parameters:
Name Type Description
color Object | String
offset Number
Source:
Returns:
Type
String
Example
var c = new ludo.color.Color();
var color = '#80994d'; // Green color with a saturation of 50
color = c.offsetSaturation(color, 10); // Increase saturation by 10 points
console.log(color); // outputs #85995C

randomColor() → {string}

Function returning a random color

Source:
Returns:
Type
string
Example
var util = new ludo.color.Color();
var color = util.randomColor(); // returns color in #RRGGBB format

rgbCode(a, b, c) → {string}

Converts RGB or HSV color object to rgb code

Parameters:
Name Type Description
a number
b number
c number
Source:
Returns:
Type
string
Example
var c = new ludo.color.Color();
console.log(c.rgbCode({r:100,g:125,b:200});
console.log(c.rgbCode({h:144,s:45,b:55});

rgbColors(a) → {object}

Converting color into RGB Object. This method accepts color in HSV format({h:120,s:40,v:100})
and in string format(RGB), example: '#669900'

Parameters:
Name Type Description
a object | String
Source:
Returns:
Type
object
Example
var util = new ludo.color.Color();
console.log(util.rgbColors('#669900');
console.log(util.rgbColors({ h: 300, s: 100, v: 50 });

rgbObject(rgbColor) → {Object}

Converts rgb color string to rgb color object

Parameters:
Name Type Description
rgbColor string
Source:
Returns:
Type
Object
Example
var c = new ludo.color.Color();
console.log(c.rgbObject('#FFEEDD');
// returns { 'r': 'FF','g' : 'EE', 'b' : 'DD' }

toHSV(color) → {Object}

Converts a RGB color to HSV(Hue, Saturation, Brightness)

Parameters:
Name Type Description
color String | Object
Source:
Returns:
Type
Object
Example
var c = new ludo.color.Color();
console.log(c.toHSV('#7e8080'));
// outputs {h: 180, s: 1.5624999999999944, v: 50.19607843137255}

toHSVFromRGB(r, g, b) → {Object}

Converts red,green and blue to HSV(Hue, Saturation, Brightness)

Parameters:
Name Type Description
r
g
b
Source:
Returns:
Type
Object
Example
var c = new ludo.color.Color();
var hsv = c.toHSVFromRGB(100,200,10);
console.log(hsv);

toRGB(red, green, blue) → {String}

Converts rgb object to rgb string

Parameters:
Name Type Description
red Number
green Number
blue Number
Source:
Returns:
Type
String
Example
var c = new ludo.color.Color();
console.log(c.toRgb(100,14,200));