creating a class for working with colors: (part I)
from matplotlib import colors as colours
from skimage import color as colour
class COLOR_SYSTEM:
def random_hex(self):
''' Generate a random Hex String '''
return str(["#"+''.join([choice(hex_string)
for loop in range(6)])]).strip("\[\]\'")
def hex2rgb(self, colorstring): # requires a HEX notated value
''' convert #RRGGBB to an (R, G, B) tuple '''
colorstring = colorstring.lstrip('#')
return tuple(int(colorstring[_hex:_hex+2], 16) for _hex in (0, 2, 4))
def rgb2hsv(self, r, g, b):
''' convert (R, G, B) to (H, S, V) tuple '''
(r, g, b) = self.rgb2posercol((r, g, b))
return tuple(colours.rgb_to_hsv((r, g, b)))
def rgb2posercol(self, rgb):
''' convert (R, G, B) to Poser Notation '''
return tuple([x/255.0 for x in rgb])#
def posercol2html(self, col_tuple):
''' convert Poser Notation to HEX '''
return self.rgb2htmlcolor(col_tuple)
def rgb2htmlcolor(self, rgb_tuple):
''' convert (R, G, B) to Hex '''
return '#%02x%02x%02x'.upper() % rgb_tuple
Locked Out