from colormap import rgb2hex
from colormap import hex2rgb
print(rgb2hex(255, 255, 255))
print(hex2rgb('#FFFFFF'))
>>> #FFFFFF
>>> (255, 255, 255)
def RGBToHex(r, g, b):
return '#%02X%02X%02X' % (r, g, b)
print(RGBToHex(255, 255, 255))
# Convert RGB to HEX
rgb = (255,255,255) # ---------> pure white
print("#%02x%02x%02x" % rgb) # -----> #ffffff
# - sabz
def rgb(r, g, b):
# convert out of range values for r
if r > 255:
r = 255
elif r < 0:
r = 0
# convert out of range values for g
if g > 255:
g = 255
elif g < 0:
g = 0
# convert out of range values for b
if b > 255:
b = 255
elif b < 0:
b = 0
#Return the hex values
return ('{:02x}{:02x}{:02x}'.format(r,g,b)).upper()
import matplotlib
print(matplotlib.colors.to_hex([ 0.47, 0.0, 1.0 ]))
print(matplotlib.colors.to_hex([ 0.7, 0.321, 0.3, 0.5 ], keep_alpha=True))
print(matplotlib.colors.to_rgb("#aabbcc"))
print(matplotlib.colors.to_rgb("#ddee9f"))