Package: chromato
🍅 chromatoFresh color utilities for PythonColor spaces: CMYK, HEX, RGB, HSL, HSVColor class: Convenience class for color manipulationOperations: shade, tone, tint, grayscale, invert, complement, add, subtract, multiplyConversion: Convert any color space to any color spaceParsingValidation(zero dependecies!)InstallpipinstallchromatoExample usageColor classfromchromato.spacesimportColorred=Color(255,0,0)red.cmyk# CMYK(c=0, m=100, y=100, k=0)red.hex# HEX(ff0000)red.rgb# RGB(r=255, g=0, b=0)red.hsl# HSL(h=0, s=1, l=0.5)red.hsv# HSV(h=0, s=1, v=1)Operationsfromchromatoimportoperationsfromchromato.spacesimportRGBred=RGB(255,0,0)blue=RGB(0,0,255)operations.add(red,blue)# RGB(r=255, g=0, b=255)operations.blend(red,blue).rgb# RGB(r=128, g=0, b=128)operations.invert(red).rgb# RGB(r=0, g=255, b=255)operations.tint(red,0.1).rgb# RGB(r=255, g=26, b=26)Conversionfromchromatoimportconvertconvert.rgb_to_hex(255,0,0)# HEX(ff0000)convert.hex_to_rgb("ff0000")# RGB(r=255, g=0, b=0)convert.hex_to_cmyk("f0f")# CMYK(c=0, m=100, y=0, k=0)APIColor spacesNamePropertiesRangeCMYKc,m,y,k0-100,0-100,0-100,0-100HEX(is a string)000000-ffffffHSLh,s,l0-1,0-1,0-1HSVh,s,v0-1,0-1,0-1RGBr,g,b0-255,0-255,0-255fromchromato.spacesimportCMYK,HEX,HSL,HSV,RGBred_cmyk=CMYK(0,100,100,0)red_hex=HEX("ff0000")red_hsl=HSL(0,1,0.5)red_hsv=HSV(0,1,1)red_rgb=RGB(255,0,0)Color classPropertiesfromchromato.spacesimportColorred=Color(255,0,0)red.cmyk# CMYK(c=0, m=100, y=100, k=0)red.hex# HEX(ff0000)red.hsl# HSL(h=0, s=1, l=0.5)red.hsv# HSV(h=0, s=1, v=1)red.rgb# RGB(r=255, g=0, b=0)Construct# examples below are equalColor(255,0,0)Color((255,0,0))Color([255,0,0])Color({"r":255,"g":0,"b":0})Color("ff0000")Color("ff0")Color(Color(255,0,0))Color(RGB(255,0,0))Color(HEX("ff0"))Color(HSV(0,1,1))Color(HSL(0,1,0.5))Color(CMYK(0,100,100,0))OperationsEach operation take one or several color values and returns aColorinstance.OperationDescriptionadd(color1, color2)Add colorsblend(color1, color2, factor)Blend/mix colorscomplement(color)Complementary colorhsv_mod(color, hue_shift, saturation_shift, value_shift)HSV modificationinvert(color)Invert colormultiply(color1, color2)Multiply colorsshade(color, factor)Increase darkness (blend with black)subtract(color1, color2)Subtract colorstint(color, factor)Increase lightness (blend with white)tone(color, factor)Reduce colorfullness (blend with gray)Arguments:color<any>,factor <float> [0-1]Returns: instance ofColorExamplefromchromato.spacesimportRGBfromchromato.operationsimportblend,invertwhite=RGB(255,255,255)black=RGB(0,0,0)blend(white,black).rgb# RGB(r=128, g=128, b=128)blend(white,black,0.2).rgb# RGB(r=204, g=204, b=204)blend(white,black,0.8).rgb# RGB(r=51, g=51, b=51)invert(black).rgb# RGB(r=255, g=255, b=255)invert((255,0,0)).cmyk# CMYK(c=0, m=100, y=100, k=0)invert("ff0000").hex# HEX(00ffff)ConversionConvert any color space to any color space.🔀RGBHEXCMYKHSLHSVRGBhex_to_rgbcmyk_to_rgbhsl_to_rgbhsv_to_rgbHEXrgb_to_hexcmyk_to_hexhsl_to_hexhsv_to_hexCMYKrgb_to_cmykhex_to_cmykhsl_to_cmykhsv_to_cmykHSLrgb_to_hslhex_to_hslcmyk_to_hslhsv_to_hslHSVrgb_to_hsvhex_to_hsvcmyk_to_hsvhsl_to_hsvExamplefromchromatoimportconvertconvert.rgb_to_cmyk(255,0,0)# CMYK(c=0, m=100, y=100, k=0)convert.rgb_to_hex(255,0,0)# HEX(ff0000)convert.rgb_to_hex(255,0,0)# HEX(ff0000)convert.rgb_to_hsl(255,0,0)# HSL(h=0, s=1, l=0.5)convert.rgb_to_hsv(255,0,0)# HSV(h=0, s=1, v=1)ParsingEach parse function takes any kind of value and tries to parse it.FunctionReturnsDescriptionparse_cmyk(value)tuple(c,m,y,k)Parse value as CMYKparse_hex(value)str(hex)Parse value as HEXparse_hsl(value)tuple(h,l,s)Parse value as HSLparse_hsv(value)tuple(h,s,v)Parse value as HSVparse_rgb(value)tuple(r,g,b)Parse value as RGBExamplefromchromatoimportparsefromchromato.spacesimportColor,HEX,RGBparse.parse_hex("f")# "ffffff"parse.parse_hex("f60")# "ff6600"parse.parse_hex("ff6600")# "ff6600"parse.parse_hex(" #ff6600 ")# "ff6600"parse.parse_hex(333)# "333333"parse.parse_hex(HEX("ff6600"))# "ff6600"parse.parse_hex(RGB(255,102,0))# "ff6600"parse.parse_hex(Color(255,102,0))# "ff6600"ValidationEach validation function validates type and range. ReturnsTrue/False.fromchromatoimportvalidationvalidation.is_cmyk(c,m,y,k)validation.is_hex(hex)validation.is_hsl(h,s,l)validation.is_hsv(h,s,v)validation.is_rgb(r,g,b)DevelopmentSetupInstallpoetrypoetry installTestsRun tests on changes in source code or tests.poetryrunptw--clear--runner"poetry run pytest --cov -vv"Code formatting (black)poetryrunblack.