in reply to [OT] Ordering colors
I had this in my notes, so I'd calculate the luma and sort by luma
You probably want to shift hue, but not saturation or value. So, convert your RGB value into HSV, add 180 degrees to H (modulo 360 +degrees of course), and convert back to RGB. function contrastingColor(color) { return (luma(color) >= 165) ? '000' : 'fff'; } function luma(color) // color can be a hx string or an array of RGB va +lues 0-255 { var rgb = (typeof color === 'string') ? hexToRGBArray(color) : col +or; return (0.2126 * rgb[0]) + (0.7152 * rgb[1]) + (0.0722 * rgb[2]); +// SMPTE C, Rec. 709 weightings } http://juicystudio.com/article/luminositycontrastratioalgorithm.php http://www.splitbrain.org/blog/2008-09/18-calculating_color_contrast_w +ith_php http://stackoverflow.com/questions/301869/how-to-find-good-looking-fon +t-color-if-background-color-is-known http://search.cpan.org/~ian/Color-Scheme-1.02/lib/Color/Scheme.pm http://colorschemedesigner.com/ http://stackoverflow.com/questions/97646/how-do-i-determine-darker +-or-lighter-color-variant-of-a-given-color http://stackoverflow.com/questions/635022/calculating-contrasting- +colours-in-javascript http://stackoverflow.com/questions/141855/programmatically-lighten +-a-color http://www.mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-mod +el-conversion-algorithms-in-javascript http://www.lighthouse.org/accessibility/effective-color-contrast http://weblogtoolscollection.com/archives/2009/04/10/how-to-highlight- +search-terms-with-jquery/ https://developer.mozilla.org/en/DOM/window.getComputedStyle
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ordering colors for contrast (luma)
by BrowserUk (Patriarch) on May 05, 2015 at 13:33 UTC | |
by Anonymous Monk on May 05, 2015 at 16:29 UTC | |
by BrowserUk (Patriarch) on May 06, 2015 at 06:58 UTC | |
|
Re^2: Ordering colors for contrast (luma)
by RonW (Parson) on May 05, 2015 at 16:59 UTC | |
by Anonymous Monk on May 05, 2015 at 18:25 UTC |