Created
September 10, 2012 18:30
-
-
Save parhammmm/3692760 to your computer and use it in GitHub Desktop.
identify whether a colour is warm/cool/neutral
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
# Shades of white | |
COLOUR_COLOUR_GHOST_WHITE = ("Ghost White", "F8F8FF") | |
COLOUR_SNOW = ("Snow","FFFAFA") | |
COLOUR_IVORY = ("Ivory","FFFFF0") | |
COLOUR_SEASHELL = ("Seashell","FFF5EE") | |
COLOUR_CORNSILK = ("Cornsilk","FFF8DC") | |
COLOUR_OLD_LACE = ("Old Lace","FDF5E6") | |
COLOUR_CREAM = ("Cream","FFFDD0") | |
COLOUR_BEIGE = ("Beige","F5F5DC") | |
COLOUR_LINEN = ("Linen","FAF0E6") | |
COLOUR_ANTIQUE_WHITE = ("Antique White","FAEBD7") | |
COLOUR_CHAMPAGNE = ("Champagne", "F7E7CE") | |
COLOUR_EGGSHELL = ("Eggshell", "F0EAD6") | |
COLOUR_BONE = ("Bone","E3DAC9") | |
COLOUR_VANILLA = ("Vanilla","F3E5AB") | |
COLOUR_NAVAJO_WHITE = ("Navajo White","FFDEAD") | |
COLOUR_ECRU = ("Ecru","C2B280") | |
# Sades of black | |
COLOUR_MIDNIGHT_BLUE = ("Midnight blue","191970") | |
COLOUR_DIM_GRAY = ("Dim gray","696969") | |
COLOUR_EBONY = ("Ebony","555D50") | |
COLOUR_TAUPE = ("Taupe","483C32") | |
COLOUR_DAVYS_GRAY = ("Davy's gray","555555") | |
COLOUR_CHARCOAL = ("Charcoal","36454F") | |
COLOUR_OUTER_SPACE = ("Outer space","414A4C") | |
COLOUR_CAFE_NOIR = ("Cafe Noir","4B3621") | |
COLOUR_BLACK_BEAN = ("Black Bean","3D0C02") | |
COLOUR_BLACK_OLIVE = ("Black Olive","3B3C36") | |
COLOUR_ONYX = ("Onyx","353839") | |
COLOUR_PHTHALO_GREEN = ("Phthalo Green","123524") | |
COLOUR_JET = ("Jet","343434") | |
COLOUR_BLACK_LEATHER_JACKET = ("Black Leather Jacket","253529") | |
COLOUR_LICORICE = ("Licorice","1A1110") | |
SHADES_WHITE = ( | |
COLOUR_COLOUR_GHOST_WHITE, | |
COLOUR_SNOW, | |
COLOUR_IVORY, | |
COLOUR_SEASHELL, | |
COLOUR_CORNSILK, | |
COLOUR_OLD_LACE, | |
COLOUR_CREAM, | |
COLOUR_BEIGE, | |
COLOUR_LINEN, | |
COLOUR_ANTIQUE_WHITE, | |
COLOUR_CHAMPAGNE, | |
COLOUR_EGGSHELL, | |
COLOUR_BONE, | |
COLOUR_VANILLA, | |
COLOUR_NAVAJO_WHITE, | |
COLOUR_ECRU, | |
) | |
SHADES_BLACK = ( | |
COLOUR_MIDNIGHT_BLUE, | |
COLOUR_DIM_GRAY, | |
COLOUR_EBONY, | |
COLOUR_TAUPE, | |
COLOUR_DAVYS_GRAY, | |
COLOUR_CHARCOAL, | |
COLOUR_OUTER_SPACE, | |
COLOUR_CAFE_NOIR, | |
COLOUR_BLACK_BEAN, | |
COLOUR_BLACK_OLIVE, | |
COLOUR_ONYX, | |
COLOUR_PHTHALO_GREEN, | |
COLOUR_JET, | |
COLOUR_BLACK_LEATHER_JACKET, | |
COLOUR_LICORICE, | |
) | |
class ColourScheme: | |
value = None | |
def __init__(self, colour_hex_code): | |
self.value = colour_hex_code.lstrip('#') | |
def is_neutral (self): | |
r, g, b = self.hex_to_rgb (self.value) | |
if r == g == b: | |
# Shade of grey | |
return True | |
for name, hex_code in SHADES_BLACK: | |
if self.value == hex_code: | |
return True | |
for name, hex_code in SHADES_WHITE: | |
if self.value == hex_code: | |
return True | |
return False | |
def is_warm (self): | |
red, green, blue = self.hex_to_rgb (self.value) | |
return ( red > blue and not self.is_neutral() ) | |
def is_cool (self): | |
red, green, blue = self.hex_to_rgb (self.value) | |
return ( blue > red and not self.is_neutral() ) | |
def hex_to_rgb(self, value): | |
lv = len(value) | |
return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3)) | |
def rgb_to_hex(self, rgb): | |
return '#%02x%02x%02x' % rgb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment