random.js
a color API for working with colors defined as 0 - 0xffffff
rationale
I wanted a simple function-based package to manipulate colors in either hex-string format '#ffffff' (for css) or hex-number format 0xffffff (for pixi.js)
Installation
npm i yy-color
API
/** * converts a #FFFFFF to 0x123456 * @param * @return */ /** * converts a 0x123456 to #FFFFFF * @param * @return */function hexToPound(color) /** * converts a number to #FFFFFF * @param * @return */function valueToPound(color) /** * based on tinycolor * https://github.com/bgrins/TinyColor * BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE * @param * @returns */function hexToHsl (color) /** based on tinycolor* https://github.com/bgrins/TinyColor* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE* @param* @param* @param* @returns number*/function hslToHex(color) /** based on tinycolor* https://github.com/bgrins/TinyColor* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE* @param* @param*/function saturate(color, amount) /** based on tinycolor* https://github.com/bgrins/TinyColor* BSD license: https://github.com/bgrins/TinyColor/blob/master/LICENSE* @param* @param*/function desaturate(color, amount) /** * blends two colors together * @param * @param * @param * @return */function blend(percent, color1, color2) /** * returns a hex color into an rgb value * @param * @return */function hexToRgb(hex) /** * rgb color to hex in the form of 0x123456 * @param * @param * @param * @return */function rgbToHex(r, g, b) /** * returns a random color with balanced r, g, b values (i.e., r, g, b either have the same value or are 0) * @param * @param * @return */function random(min, max) /** * returns a random color based on hsl * @param * @param * @param * @param * @param * @param */function randomHSL(hMin, hMax, sMin, sMax, lMin, lMax) /** * returns random colors based on HSL with different hues * based on http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ * @returns */function randomGoldenRatioHSL(count, saturation, luminosity)