avp / spectra

A Javascript color library. Quickly manipulate and convert colors.
avp.github.io/spectra
MIT License
237 stars 18 forks source link

Light and dark #3

Closed avp closed 10 years ago

avp commented 10 years ago

Find out if a color would be classified as light and/or dark.

For example, when using light colors, dark text looks good. So we need a function light() that returns true if the color is light and false otherwise.

From http://24ways.org/2010/calculating-color-contrast/:

function getContrastYIQ(){
    var yiq = ((r*299)+(g*587)+(b*114))/1000;
    return (yiq >= 128) ? 'dark' : 'light';
}