It provides color string parsing, format converting and basic color adjusting methods.
Supported color formats:
kolor.jsin your HTML document:
Core functionalities are provided by the
kolorobject in global scope.
Working with RequireJS (or other AMD compatible loaders)
Just require the named module
Working with npmnpm install kolor
Creating a color object
Colors may be created in the following ways:
By parsing a given string valuevar red = //color namegreen = //valid CSS expressionsblue = //more valid CSS expressionscyan = //not supported by CSS but has a similar syntaxmagenta = //hex RGB valueyellow = //hex RGB value without '#'purple = ; // named hues
Color names are defined by W3C SVG color names used in CSS3.
Names or hex values will generate RGB colors.
By specifying a color formatvar red = kolor //can use either number or percent stringgreen = kolor //using arrayblue = kolor; //using object
By cloning another color objectvar red =newRed = ;
Created colors are in certain formats and can be converted to other formats.
kolor provides jQuery-like accessors for color objects.
color; //altering 'red' channelcolor; //shorthand method is also available
Setters return color object itself so we can do a bit of chaining:
color; //making it lighter
When setting a value of a channel, the specified value will be automatically restricted within a valid range according to the channel configuration.
console; //255console; //350console; //1
Once a color object is created, it can be easily converted to other formats. After each conversion, a new color object will be produced and returned.
var hsvColor = rgbColor; //converts and sets
console; //'#ff0000'console; //'rgb(255, 0, 0)'
A color can be modified into another in many ways. After each modification, a new color object is produced and returned.
color = red; //spins the color wheel for 180 degreescolor = red; //mixes two colors with a given proportion.color = red; //gets a lighter color