Created
March 6, 2009 16:49
-
-
Save andrew/74970 to your computer and use it in GitHub Desktop.
This file contains 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
# takes a hex value of a colour (0xffffff) and returns either black or white, which ever is easier to see | |
def black_or_white(hex) | |
rgb = {} | |
%w(r g b).inject(hex) {|a,i| rest, rgb[i] = a.divmod 256; rest} | |
r = rgb['r']/255 | |
g = rgb['g']/255 | |
b = rgb['b']/255 | |
[r, g, b].max > 0.55 ? "#000000" : "#FFFFFF" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment