ColorPrism
Simple color manipulation functions.
Compatible for both Node.js and browser apps.
Installation
Download from CDN or install from npm
npm install --save color-prism
Usage
Node.js
On Node.js all the methods are available in the package level
// Import the packageconst ColorPrism = ; // Create a new rgb color object;const rgbColor = ColorPrism;
Browser
On browsers, there are 3 aways to access the library:
- Use
ColorPrism
global object directly. - Use
window.ColorPrism
instead. - Use the methods directly. However the constants object will not be available this way.
Reference
- ColorPrism
- degreesToRad(degrees) ⇒
number
- RGB(r, g, b) ⇒
RGB
- .normalize() ⇒
RGB
- .grayScale() ⇒
RGB
- .normalize() ⇒
- rgb(r, g, b) ⇒
RGB
- HSL(h, s, l) ⇒
HSL
- hsl(h, s, l) ⇒
HSL
- CMYK(c, m, y, k) ⇒
CMYK
- cmyk(c, m, y, k) ⇒
CMYK
- rgbToHsl(r, g, b) ⇒
HSL
- hslToRgb(h, s, l) ⇒
RGB
- rgbToCmyk(r, g, b) ⇒
CMYK
- cmykToRgb(c, m, y, k) ⇒
RGB
- normalize(r, g, b) ⇒
RGB
- grayScale(r, g, b) ⇒
RGB
- hue(h, r, g, b) ⇒
RGB
- saturation(s, r, g, b) ⇒
RGB
- lighting(l, r, g, b) ⇒
RGB
- cyan(c, r, g, b) ⇒
RGB
- magenta(m, r, g, b) ⇒
RGB
- yellow(y, r, g, b) ⇒
RGB
- degreesToRad(degrees) ⇒
number
degreesToRad(degrees) ⇒ Convert degrees to radian
Kind: inner method of ColorPrism
Param | Type |
---|---|
degrees | number |
RGB
RGB(r, g, b) ⇒ RGB class for storing color values
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
r | number |
red value (0..255) or {RGB} instance or {CMYK} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
RGB.normalize() ⇒ Change the range from 0 to 255
to 0 to 1
Kind: instance method of RGB
RGB
RGB.grayScale() ⇒ Get a gray scale rgb color from this color
Kind: instance method of RGB
RGB
rgb(r, g, b) ⇒ RGB helper function
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
HSL
HSL(h, s, l) ⇒ HSL class for storing color values
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
h | number |
hue value (0..2PI) or {HSL} instance |
s | number |
saturation value (0..1) |
l | number |
lighting value (0..1) |
HSL
hsl(h, s, l) ⇒ HSL helper function
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
h | number |
hue value (0..2PI) or {HSL} instance |
s | number |
saturation value (0..1) |
l | number |
lighting value (0..1) |
CMYK
CMYK(c, m, y, k) ⇒ CMYK class for storing color values
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
c | number |
cyan value (0..1) or {CMYK} instance or {RGB} instance |
m | number |
magenta value (0..1) |
y | number |
yellow value (0..1) |
k | number |
black key value (0..1) |
CMYK
cmyk(c, m, y, k) ⇒ CMYK helper function
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
c | number |
cyan value (0..1) or {CMYK} instance or {RGB} instance |
m | number |
magenta value (0..1) |
y | number |
yellow value (0..1) |
k | number |
black key value (0..1) |
HSL
rgbToHsl(r, g, b) ⇒ Method to convert RGB to HSL
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
hslToRgb(h, s, l) ⇒ Method to convert HSL to RGB
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
h | number |
hue value (0..2PI) or {HSL} instance |
s | number |
saturation value (0..255) |
l | number |
lighting value (0..255) |
CMYK
rgbToCmyk(r, g, b) ⇒ Method to convert RGB to CMYK
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
cmykToRgb(c, m, y, k) ⇒ Method to convert CMYK to RGB
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
c | number |
cyan value (0..1) or {CMYK} instance |
m | number |
magenta value (0..1) |
y | number |
yellow value (0..1) |
k | number |
black key value (0..1) |
RGB
normalize(r, g, b) ⇒ Change the range of a RGB color from 0 to 255
to 0 to 1
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
grayScale(r, g, b) ⇒ Get a gray scale rgb color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
r | number |
red value (0..255) or {RGB} instance or {CMYK} instance or {HSL} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
hue(h, r, g, b) ⇒ Change the hue value of a RGB color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
h | number |
hue value (0..2PI) |
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
saturation(s, r, g, b) ⇒ Change the saturation value of a RGB color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
s | any |
saturation value (0..1) |
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
lighting(l, r, g, b) ⇒ Change the lighting value of a RGB color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
l | any |
lighting value (0..1) |
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
cyan(c, r, g, b) ⇒ Change the cyan tone of a RGB color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
c | any |
lighting value (0..1) |
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
magenta(m, r, g, b) ⇒ Change the magenta tone of a RGB color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
m | any |
lighting value (0..1) |
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |
RGB
yellow(y, r, g, b) ⇒ Change the yellow tone of a RGB color
Kind: inner method of ColorPrism
Param | Type | Description |
---|---|---|
y | any |
lighting value (0..1) |
r | number |
red value (0..255) or {RGB} instance |
g | number |
green value (0..255) |
b | number |
blue value (0..255) |