av.color: a JavaScript library to deal with colors
This tiny lib eases the way you manage the colors in your app by encapsulating everything in an object.
This is v. 1.0.0, so there's a lot of room for improvement.
Constructor
There are several ways to summon a Color
:
// no parameters => blackvar mycolor = ;// HTML5 color namevar mycolor = 'Red'; // Hexadecimal expresionvar mycolor = hex:'#FF0000';// RGB vectorvar mycolor = rgb:25500;// HSL vectorvar mycolor = hsl:0 1 05;// HSV vectorvar mycolor = hsv:0 1 1;
Properties
// HTML5 name (if any)mycolorHTML5 = 'Red';// RGB valuesmycolorrgb = 255 0 0;mycolorred = 255;mycolorgreen = 0;mycolorblue = 0;// HEX expresionmycolorhex = '#FF0000';// HSL vectormycolorhsl = 0 1 05;// HSV vectormycolorhsv = 0 1 1;// Luminancemycolorluminance = 05;// Saturationmycolorsaturation = 1;// Huemycolorhue = 1;
Methods
// Inverts the colormycolor;
Functions
// HEX to RGBColor// RGB to HEXColor;// RGB to HSLColor;// HSL to RGBColor;// RGB to HSLColor;// HSL to RGBColor;// Change the luminance in a factor [0-1]Color;// Retrieves the hex value for an HTML5 color nameColor;// Inverts a color from its hex expresionColor;// Interpolates between colors at a percent valueColor;
Gradients
This object lets you define a color scale and get an interpolated value at any point from 0 to 100. Just declare an array of {stop, color}
steps, where:
- stop: integer 0-100
- color: HTML5 name, hex expresion, RGB vector, HSV vector or HSL vector
mygradient = stop: 0 color: '{rgb:[255,0,0]}' stop: 50 color: '#FFFF00' stop: 100 color: 'Lime' ;
Then you can retrieve the value in the scale like:
mygradient;