add function to calculate grayscale of a color
This commit is contained in:
13
src/utils.js
13
src/utils.js
@@ -130,6 +130,19 @@ export function getColor ({red, green, blue, alpha}) {
|
|||||||
`rgb(${ red }, ${ green }, ${ blue })`;
|
`rgb(${ red }, ${ green }, ${ blue })`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GRAY_FACTOR = {
|
||||||
|
red: 0.299,
|
||||||
|
green: 0.587,
|
||||||
|
blue: 0.114,
|
||||||
|
};
|
||||||
|
|
||||||
|
// grayscale accounting for luminosity
|
||||||
|
export function grayscale ({red, green, blue}) {
|
||||||
|
return GRAY_FACTOR.red * red
|
||||||
|
+ GRAY_FACTOR.green * green
|
||||||
|
+ GRAY_FACTOR.blue * blue;
|
||||||
|
}
|
||||||
|
|
||||||
export function extend (obj, ...sources) {
|
export function extend (obj, ...sources) {
|
||||||
return Object.assign({}, obj, ...sources);
|
return Object.assign({}, obj, ...sources);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user