Created
December 30, 2011 16:14
-
-
Save marcelklehr/1540463 to your computer and use it in GitHub Desktop.
Calculate contrast from two RGB colors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function contrast(c1, c2) { | |
v1 = Math.min(Math.min(c1.r, c1.g),c1.b) + Math.max(Math.max(c1.r, c1.g),c1.b) / 2; | |
v2 = Math.min(Math.min(c2.r, c2.g),c2.b) + Math.max(Math.max(c2.r, c2.g),c2.b) / 2; | |
return Math.abs(v1-v2); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contrast({r:0, g:0, b:0},// black | |
{r:128, g:83, b:83}// light-brown-red | |
); | |
// 147 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment