add function to calculate grayscale of a color

This commit is contained in:
Gavin McDonald
2018-09-13 21:04:28 -04:00
parent f406dfd63b
commit 49cea85115

View File

@@ -130,6 +130,19 @@ export function getColor ({red, green, blue, alpha}) {
`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) {
return Object.assign({}, obj, ...sources);
}