The color namespace of Bijou.js
Methods
# static exports.blendColors(color1, color2, percentopt) → {String}
Blends two colors through additive blending by a percentage.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
color1 |
String
|
The hex code of the first color to be blended |
||
color2 |
String
|
The hex code of the second color to be blended. |
||
percent |
Number
|
<optional> |
50 | A number between 0 and 100 of the percentage to blend the two colors, 0 being completely the first color and 100 being completely the second color. |
The blended color (A hex code).
String
Example
console.log(_$.blendColors("#ffffff", "#000000", 80)); // #333333
# static exports.hexToRGB(hex) → {String}
Converts a hex code to a RGB color.
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
String
|
The hex code to convert. |
The RGB color converted from the hex code.
String
Example
console.log(_$.rgbToHex("#ffffff")); // "rgb(255,255,255)"
# static exports.lightOrDark(color) → {Object}
Tests if a color is light or dark and returns an object representation.
Parameters:
| Name | Type | Description |
|---|---|---|
color |
string
|
The hex color to test. |
An object that represents if the color is light or dark and how much. The object key "hsp" represents a value out of 255 of how light the color is and the object's key "lightOrDark" is a string (Either "light" or "dark") of whether the color is light or dark.
Object
Example
if (_$.lightOrDark("#333333").lightOrDark === 'dark'){
document.querySelector("DIV").style.color = "white";
} else {
document.querySelector("DIV").style.color = "black";
}
# static exports.lightenColor(col, amt) → {String}
Lighten or darken a color by a certain amount
Parameters:
| Name | Type | Description |
|---|---|---|
col |
String
|
The color to lighten/darken |
amt |
Number
|
The amount to lighten the color (out of 255). |
The color lightened.
String
Example
_$.lightenColor("#000000", 50); // #323232
# static exports.randomColor() → {String}
Generates a random hex color.
A random Hex color
String
Example
console.log(_$.randomColor()); // e.g. #5bf462
# static exports.rgbToHex(rgb) → {String}
Converts a rgb(a) color to hex.
Parameters:
| Name | Type | Description |
|---|---|---|
rgb |
String
|
The string of RGB colors. |
The hex color.
String
Example
console.log(_$.rgbToHex("rgb(255,255,255)")); // "#ffffff"