Color Forge
A simple color system based on the work of https://github.com/dfcreative/color-space
npm install color-forge
var colorForge = ;
See doc.md
for full documentation.
Basic Usage
Creating a Color Instance
Colors can be made with the regular constructor pattern with the parameters
values, alpha = 1, space = 'rgb'
.
var color = 255 0 0 1 'rgb';
or since the alpha defaults to 1, and the color space defaults to 'rgb', this can be written as follows.
var color = ;
To create a color in a specific space, you may also use the following
shorthand, which accepts the parameters values, alpha = 1
.
var color = Color;var color = Color;
In addition, you can create a color from a hex code as follows, with the leading hash (#) being optional.
Color;Color;Color; // has alpha of ~0.26Color; // has alpha of ~0.26 Color;
You can also create a color from a css name.
Color;
See color-space for supported color spaces (it's pretty much all of them).
The format of a color object is as follows.
color space values alpha /* semi-private */ originalColor
Converting Colors
color;
The result is a new object, and does not affect the original object. Additionally, the new object will store the original color, meaning unlimited conversions without loss.
assert;
Mixing Colors
Accepts the paremeters otherColor, amount = 0.5, mode = 'rgb'
. Returns a new color object with the colors mixed according to amount (an amount of 0 gives color1, and 1 gives color2). Specifying a different mode will mix the color via that mode, allowing you to get even color spaces.
color1;
Color Operations
color1;
All operations accept a color as the first and only argument. The available color operations are add
, subtract
, multiply
, divide
, screen
, overlay
, dodge
, burn
.
All operations are done via RGB.
Extra
color1; // Gives a string like 'hsl(180, 60, 20)'color1; // Gives the hex codecolor1; // Gives css value if exactly identical, else nullcolor1; // Gives closest css
Licence
MIT