### Gamut Mapping Examples in Perceptual Spaces Source: https://facelessuser.github.io/coloraide/gamut Examples of fitting colors to the sRGB gamut using different perceptual spaces as the target for raytracing. ```python >>> yellow = Color('color(display-p3 1 1 0)') >>> lightness_mask = Color('oklch(0% none none)') >>> Steps([c.fit('srgb', method='raytrace', pspace='oklch') for c in Color.steps([yellow, lightness_mask], steps=20, space='oklch')]) [color(--oklch 0.96476 0.21094 110.23deg / 1), color(--oklch 0.91399 0.19984 110.23deg / 1), color(--oklch 0.86321 0.18874 110.23deg / 1), color(--oklch 0.81243 0.17763 110.23deg / 1), color(--oklch 0.76166 0.16653 110.23deg / 1), color(--oklch 0.71088 0.15543 110.23deg / 1), color(--oklch 0.6601 0.14433 110.23deg / 1), color(--oklch 0.60932 0.13323 110.23deg / 1), color(--oklch 0.55855 0.12212 110.23deg / 1), color(--oklch 0.50777 0.11102 110.23deg / 1), color(--oklch 0.45699 0.09992 110.23deg / 1), color(--oklch 0.40622 0.08882 110.23deg / 1), color(--oklch 0.35544 0.07772 110.23deg / 1), color(--oklch 0.30466 0.06661 110.23deg / 1), color(--oklch 0.25389 0.05551 110.23deg / 1), color(--oklch 0.20311 0.04441 110.23deg / 1), color(--oklch 0.15233 0.03331 110.23deg / 1), color(--oklch 0.10155 0.0222 110.23deg / 1), color(--oklch 0.05078 0.0111 110.23deg / 1), color(--oklch 0 0 none / 1)] ``` ```python >>> yellow = Color('color(display-p3 1 1 0)') >>> lightness_mask = Color('color(--lch99o 0% none none)') >>> Steps([c.fit('srgb', method='raytrace', pspace='lch99o') for c in Color.steps([yellow, lightness_mask], steps=20, space='lch99o')]) [color(--lch99o 97.304 20.716 98.051deg / 1), color(--lch99o 92.182 43.933 97.877deg / 1), color(--lch99o 87.061 42.844 97.877deg / 1), color(--lch99o 81.94 41.72 97.877deg / 1), color(--lch99o 76.819 40.558 97.877deg / 1), color(--lch99o 71.697 39.356 97.877deg / 1), color(--lch99o 66.576 38.109 97.877deg / 1), color(--lch99o 61.455 36.813 97.877deg / 1), color(--lch99o 56.334 35.464 97.877deg / 1), color(--lch99o 51.212 34.055 97.877deg / 1), color(--lch99o 46.091 32.58 97.877deg / 1), color(--lch99o 40.97 31.031 97.877deg / 1), color(--lch99o 35.849 29.399 97.877deg / 1), color(--lch99o 30.727 27.581 97.877deg / 1), color(--lch99o 25.606 25.272 97.877deg / 1), color(--lch99o 20.485 22.368 97.877deg / 1), color(--lch99o 15.364 18.721 97.877deg / 1), color(--lch99o 10.242 14.071 97.877deg / 1), color(--lch99o 5.1212 8.0424 97.877deg / 1), color(--lch99o 0 0 none / 1)] ``` ```python >>> yellow = Color('color(display-p3 1 1 0)') >>> lightness_mask = Color('color(--hct none none 0%)') >>> Steps([c.fit('srgb', method='raytrace', pspace='hct') for c in Color.steps([yellow, lightness_mask], steps=20, space='hct')]) [color(--hct 111.07deg 75.366 96.849 / 1), color(--hct 111.07deg 72.594 91.752 / 1), color(--hct 111.07deg 69.788 86.655 / 1), color(--hct 111.07deg 66.946 81.557 / 1), color(--hct 111.07deg 64.066 76.46 / 1), color(--hct 111.07deg 61.147 71.363 / 1), color(--hct 111.07deg 58.186 66.265 / 1), color(--hct 111.07deg 55.18 61.168 / 1), color(--hct 111.07deg 52.127 56.071 / 1), color(--hct 111.07deg 49.024 50.973 / 1), color(--hct 111.07deg 45.866 45.876 / 1), color(--hct 111.07deg 42.649 40.779 / 1), color(--hct 111.07deg 39.368 35.681 / 1), color(--hct 111.07deg 36.015 30.584 / 1), color(--hct 111.07deg 32.581 25.487 / 1), color(--hct 111.07deg 29.056 20.389 / 1), color(--hct 111.07deg 25.424 15.292 / 1), color(--hct 111.07deg 21.666 10.195 / 1), color(--hct 111.07deg 17.402 5.0973 / 1), color(--hct none 0 0 / 1)] ``` ```python >>> yellow = Color('color(display-p3 1 1 0)') >>> lightness_mask = Color('jzczhz(0% none none)') >>> Steps([c.fit('srgb', method='raytrace', pspace='jzczhz') for c in Color.steps([yellow, lightness_mask], steps=20, space='jzczhz')]) ``` -------------------------------- ### Initialize and stringify xyY colors Source: https://facelessuser.github.io/coloraide/colors/xyy Examples of creating color objects in the xyY space and converting them to string representations. ```python >>> Color("xyy", [0.64, 0.33, 0.21264]) color(--xyy 0.64 0.33 0.21264 / 1) >>> Color("xyy", [0.50047, 0.4408, 0.48173]).to_string() 'color(--xyy 0.50047 0.4408 0.48173)' ``` -------------------------------- ### Create and stringify XYB colors Source: https://facelessuser.github.io/coloraide/colors/xyb Examples of initializing a Color object with XYB coordinates and converting it to a string representation. ```python >>> Color("xyb", [0.0281, 0.48819, -0.01653]) color(--xyb 0.0281 0.48819 -0.01653 / 1) >>> Color("xyb", [0.01132, 0.64596, -0.1149]).to_string() 'color(--xyb 0.01132 0.64596 -0.1149)' ``` -------------------------------- ### Initialize and stringify IgPgTg colors Source: https://facelessuser.github.io/coloraide/colors/igpgtg Examples of creating a Color object in the IgPgTg space and converting it to a string representation. ```python >>> Color("igpgtg", [0.54834, 0.15366, 0.43674]) color(--igpgtg 0.54834 0.15366 0.43674 / 1) >>> Color("igpgtg", [0.73238, 0.0397, 0.32108]).to_string() 'color(--igpgtg 0.73238 0.0397 0.32108)' ``` -------------------------------- ### Color conversion and string output Source: https://facelessuser.github.io/coloraide/colors/srgb_linear Examples of converting sRGB colors and generating string representations. ```python >>> Color("srgb", [1, 0, 0]) color(srgb 1 0 0 / 1) >>> Color("srgb", [1, 0.37626, 0]).to_string() 'rgb(255 95.946 0)' ``` -------------------------------- ### HWB String Representation and Formatting Source: https://facelessuser.github.io/coloraide/colors/hwb Examples of converting HWB color objects to various string formats. ```python >>> Color("hwb", [0, 0, 0]) color(--hwb 0deg 0 0 / 1) >>> Color("hwb", [38.824, 0, 0]).to_string() 'hwb(38.824 0 0)' >>> Color("hwb", [60, 0, 0]).to_string(percent=False) 'hwb(60 0 0)' >>> Color("hwb", [120, 0, 0]).to_string(color=True) 'color(--hwb 120 0 0)' ``` -------------------------------- ### String Representation and Output Source: https://facelessuser.github.io/coloraide/colors/a98_rgb Examples of converting A98 RGB colors to their string representation. ```python >>> Color('a98-rgb', [0.85859, 0, 0]) color(a98-rgb 0.85859 0 0 / 1) >>> Color('a98-rgb', [0.91489, 0.64117, 0.15031]).to_string() 'color(a98-rgb 0.91489 0.64117 0.15031)' ``` -------------------------------- ### Format Oklab string output Source: https://facelessuser.github.io/coloraide/colors/oklab Examples of converting Oklab color objects to various string representations. ```python >>> Color("oklab", [0.62796, 0.22486, 0.12585]) color(--oklab 0.62796 0.22486 0.12585 / 1) >>> Color("oklab", [0.79269, 0.05661, 0.16138]).to_string() 'oklab(0.79269 0.05661 0.16138)' >>> Color("oklab", [0.96798, -0.07137, 0.19857]).to_string(percent=True) 'oklab(96.798% -17.842% 49.643%)' >>> Color("oklab", [0.51975, -0.1403, 0.10768]).to_string(color=True) 'color(--oklab 0.51975 -0.1403 0.10768)' ``` -------------------------------- ### Color Representation and String Conversion Source: https://facelessuser.github.io/coloraide/colors/rec2100_hlg Examples of creating color objects and converting them to string representations. ```python >>> Color("rec2100-hlg", [0.65587, 0.23436, 0.11415], 1) color(rec2100-hlg 0.65587 0.23436 0.11415 / 1) >>> Color("rec2100-hlg", [0.69294, 0.56608, 0.19838], 1).to_string() 'color(rec2100-hlg 0.69294 0.56608 0.19838)' ``` -------------------------------- ### Color object string representation Source: https://facelessuser.github.io/coloraide/colors/rec2100_linear Examples of creating a color object and converting it to a string representation. ```python >>> Color("rec2100-linear", [0.6274, 0.0691, 0.01639]) color(rec2100-linear 0.6274 0.0691 0.01639 / 1) >>> Color("rec2100-linear", [0.7513, 0.41509, 0.04951]).to_string() 'color(rec2100-linear 0.7513 0.41509 0.04951)' ``` -------------------------------- ### Convert and format OkLCh colors Source: https://facelessuser.github.io/coloraide/colors/oklch Examples of creating color objects and converting them to various string representations. ```python >>> Color("oklch", [0.62796, 0.25768, 29.234]) color(--oklch 0.62796 0.25768 29.234deg / 1) >>> Color("oklch", [0.79269, 0.17103, 70.67]).to_string() 'oklch(0.79269 0.17103 70.67)' >>> Color("oklch", [0.96798, 0.21101, 109.77]).to_string(percent=True) 'oklch(96.798% 52.753% 109.77)' >>> Color("oklch", [0.51975, 0.17686, 142.5]).to_string(color=True) 'color(--oklch 0.51975 0.17686 142.5)' ``` -------------------------------- ### String Representation and Conversion Source: https://facelessuser.github.io/coloraide/colors/prophoto_rgb Examples of how ProPhoto RGB colors are represented as strings and converted to CSS format. ```python >>> Color("prophoto-rgb", [0.78951, 0.62329, 0.21172], 1) color(prophoto-rgb 0.78951 0.62329 0.21172 / 1) >>> Color("prophoto-rgb", [0.70225, 0.27572, 0.10355]).to_string() 'color(prophoto-rgb 0.70225 0.27572 0.10355)' ``` -------------------------------- ### Format Oklrab color strings Source: https://facelessuser.github.io/coloraide/colors/oklrab Examples of converting Oklrab color objects to string representations with various options. ```python >>> Color("oklrab", [0.56808, 0.22486, 0.12585]) color(--oklrab 0.56808 0.22486 0.12585 / 1) >>> Color("oklrab", [0.75883, 0.05661, 0.16138]).to_string() 'color(--oklrab 0.75883 0.05661 0.16138)' >>> Color("oklrab", [0.9627, -0.07137, 0.19857]).to_string(percent=True) 'color(--oklrab 96.27% -17.842% 49.643%)' ``` -------------------------------- ### Color Object Initialization and String Output Source: https://facelessuser.github.io/coloraide/colors/cam02_ucs Examples of initializing a CAM02 UCS color object and converting it to a string representation. ```python >>> Color("cam02-ucs", [60.054, 38.679, 24.316], 1) color(--cam02-ucs 60.054 38.679 24.316 / 1) >>> Color("cam02-ucs", [79.041, 9.9159, 31.18], 1).to_string() 'color(--cam02-ucs 79.041 9.9159 31.18)' ``` -------------------------------- ### Format OkLrCh color strings Source: https://facelessuser.github.io/coloraide/colors/oklrch Examples of converting OkLrCh color objects to string representations, including percentage formatting. ```python >>> Color("oklrch", [0.56808, 0.25768, 29.234]) color(--oklrch 0.56808 0.25768 29.234deg / 1) >>> Color("oklrch", [0.75883, 0.17103, 70.67]).to_string() 'color(--oklrch 0.75883 0.17103 70.67)' >>> Color("oklrch", [0.9627, 0.21101, 109.77]).to_string(percent=True) 'color(--oklrch 96.27% 52.753% 109.77)' ``` -------------------------------- ### Registering Plugins Source: https://facelessuser.github.io/coloraide/about/changelog Demonstrates the transition from passing plugin classes to passing instantiated plugin objects during registration. ```python # Before change: Color.register([Plugin1, Plugin2]) # After change: Color.register([Plugin1(), Plugin2(optional_parm=True)]) ``` -------------------------------- ### Install ColorAide Source: https://facelessuser.github.io/coloraide Command to install the ColorAide library using pip. ```bash $ pip install coloraide ``` -------------------------------- ### Match with start offset Source: https://facelessuser.github.io/coloraide/color Specify a start position to search for colors within a larger string buffer. ```python >>> Color.match("red and yellow", start=8) ColorMatch(color=color(srgb 1 1 0 / 1), start=8, end=14) ``` -------------------------------- ### Initialize Oklab color object Source: https://facelessuser.github.io/coloraide/colors/oklab Demonstrates manual creation of an Oklab color using raw data. ```python Color("oklab", [0, 0, 0], 1) ``` -------------------------------- ### Access channels with get() Source: https://facelessuser.github.io/coloraide/manipulation The get() function allows accessing channels by name, including channels from other color spaces. ```python >>> color = Color("pink") >>> color color(srgb 1 0.75294 0.79608 / 1) >>> color.get('red') 1.0 >>> color.get('oklch.hue') 7.085489349755127 ``` -------------------------------- ### Initialize Spectral Interpolation Source: https://facelessuser.github.io/coloraide/interpolation Demonstrates how to initialize spectral and spectral-continuous interpolators using a list of colors. ```python >>> colors = [ ... Color('#00000000'), ... Color('#002185').set('alpha', NaN), ... Color('#FFFFFFFF') ... ] >>> Color.interpolate(colors, method='spectral') >>> Color.interpolate(colors, method='spectral-continuous') ``` -------------------------------- ### get() Source: https://facelessuser.github.io/coloraide/manipulation Accesses any channel by name, including channels in other color spaces. ```APIDOC ## get(channel_name) ### Description Provides access to any channel via the channel name. It supports indirect access to channels in other color spaces. ### Parameters - **channel_name** (str) - Required - The name of the channel to retrieve (e.g., 'red' or 'oklch.hue'). ``` -------------------------------- ### Initialize Colors from CSS Strings Source: https://facelessuser.github.io/coloraide/color Demonstrates initializing color objects using standard CSS Level 3 and Level 4 color syntax. ```python >>> Color("red") color(srgb 1 0 0 / 1) >>> Color("#00ff00") color(srgb 0 1 0 / 1) >>> Color("rgb(0 0 255 / 1)") color(srgb 0 0 1 / 1) ``` -------------------------------- ### String representation and conversion Source: https://facelessuser.github.io/coloraide/colors/luv Examples of how Luv colors are represented as strings. ```python >>> Color("luv", [53.237, 175.01, 37.765]) color(--luv 53.237 175.01 37.765 / 1) >>> Color("luv", [74.934, 74.839, 74.014]).to_string() 'color(--luv 74.934 74.839 74.014)' ``` -------------------------------- ### Handle Luminance and Saturation Scaling Source: https://facelessuser.github.io/coloraide/chromaticity Demonstrates how luminance is respected during scaling, with an option to force maximum saturation. ```python >>> uv = Color('red').uv() >>> Color.chromaticity('srgb', [*uv, 0.3], scale=True) color(srgb 1 0 0 / 1) >>> Color.chromaticity('srgb', [*uv, 0.3], scale=True, max_saturation=True) color(srgb 1 0 0 / 1) ``` -------------------------------- ### String representation and conversion Source: https://facelessuser.github.io/coloraide/colors/rec2020_linear Examples of how the color object outputs its string representation. ```python >>> Color("rec2020-linear", [0.6274, 0.0691, 0.01639]) color(--rec2020-linear 0.6274 0.0691 0.01639 / 1) >>> Color("rec2020-linear", [0.7513, 0.41509, 0.04951]).to_string() 'color(--rec2020-linear 0.7513 0.41509 0.04951)' ``` -------------------------------- ### Convert LChuv to string representation Source: https://facelessuser.github.io/coloraide/colors/lchuv Examples of how LChuv color objects are represented as strings. ```python >>> Color("lchuv", [53.237, 179.04, 12.177]) color(--lchuv 53.237 179.04 12.177deg / 1) >>> Color("lchuv", [74.934, 105.26, 44.683]).to_string() 'color(--lchuv 74.934 105.26 44.683)' ``` -------------------------------- ### String representation and conversion Source: https://facelessuser.github.io/coloraide/colors/lab_d65 Examples of string output for Lab D65 color objects. ```python >>> Color("lab-d65", [53.237, 80.09, 67.203]) color(--lab-d65 53.237 80.09 67.203 / 1) >>> Color("lab-d65", [74.934, 23.927, 78.953]).to_string() 'color(--lab-d65 74.934 23.927 78.953)' ``` -------------------------------- ### Initialize Color object with OkLrCh Source: https://facelessuser.github.io/coloraide/colors/oklrch Manually create a color object using the oklrch space name. ```python Color("oklrch", [0, 0, 0], 1) ``` -------------------------------- ### Perform In-Place and Cloned Gamut Fitting Source: https://facelessuser.github.io/coloraide/about/releases/1.0 Demonstrates the default in-place behavior of fit() and how to preserve the original color by cloning before fitting. ```python >>> color1 = Color('display-p3', [1, 1, 0]) >>> color1.fit('srgb') color(display-p3 0.99226 0.99713 0.32949 / 1) >>> color1 color(display-p3 0.99226 0.99713 0.32949 / 1) >>> color2 = Color('display-p3', [0, 1, 0]) >>> color3 = color2.clone().fit('srgb') >>> color2, color3 (color(display-p3 0 1 0 / 1), color(display-p3 0.44299 0.95403 0.40694 / 1)) ``` -------------------------------- ### ACEScct String Representation Source: https://facelessuser.github.io/coloraide/colors/acescct Examples of converting ACEScct color objects to string format. ```python >>> Color("acescct", [0.51451, 0.33604, 0.23515]) color(--acescct 0.51451 0.33604 0.23515 / 1) >>> Color("acescct", [0.53009, 0.48237, 0.32561]).to_string() 'color(--acescct 0.53009 0.48237 0.32561)' ``` -------------------------------- ### Create Color from Chromaticity with Consistent White Point Source: https://facelessuser.github.io/coloraide/chromaticity Demonstrates creating a color from ProPhoto chromaticities by first initializing in the ProPhoto space to maintain white point consistency before converting to sRGB. ```python >>> c1 = Color('prophoto-rgb', [1, 0, 0]) >>> c2 = Color.chromaticity('prophoto-rgb', c1.split_chromaticity()).convert('srgb') >>> c1, c2.convert('prophoto-rgb') (color(prophoto-rgb 1 0 0 / 1), color(prophoto-rgb 1 0 0 / 1)) ``` -------------------------------- ### Generate Analogous Harmony Source: https://facelessuser.github.io/coloraide/harmonies Calculates three adjacent colors on the color wheel starting from red. ```python >>> Steps(Color('red').harmony('analogous')) [color(--oklch 0.62796 0.25768 -0.76612deg / 1), color(--oklch 0.62796 0.25768 29.234deg / 1), color(--oklch 0.62796 0.25768 59.234deg / 1)] ``` -------------------------------- ### Interpolate, Discrete, and Steps with Custom Domains Source: https://facelessuser.github.io/coloraide/interpolation Demonstrates applying a custom domain to color interpolation, discrete mapping, and step generation methods. ```python >>> Color.interpolate( ... ['blue', 'green', 'yellow', 'orange', 'red'], ... domain=[-32, 32, 60, 85, 95] ... ) >>> Color.discrete( ... ['blue', 'green', 'yellow', 'orange', 'red'], ... domain=[-32, 32, 60, 85, 95] ... ) >>> Color.steps( ... ['blue', 'green', 'yellow', 'orange', 'red'], ... steps=11, ... domain=[-32, 32, 60, 85, 95] ... ) [color(--oklab 0.45201 -0.03246 -0.31153 / 1), color(--oklab 0.46546 -0.05386 -0.22834 / 1), color(--oklab 0.4789 -0.07526 -0.14516 / 1), color(--oklab 0.49234 -0.09666 -0.06197 / 1), color(--oklab 0.50578 -0.11806 0.02122 / 1), color(--oklab 0.51922 -0.13946 0.1044 / 1), color(--oklab 0.71505 -0.11027 0.14728 / 1), color(--oklab 0.91836 -0.079 0.18851 / 1), color(--oklab 0.90067 -0.02222 0.18429 / 1), color(--oklab 0.81162 0.04279 0.1654 / 1), color(--oklab 0.62796 0.22486 0.12585 / 1)] ``` -------------------------------- ### Interpolate colors in RYB space Source: https://facelessuser.github.io/coloraide/colors/ryb Examples of creating linear interpolators between RYB color points. ```python >>> Color.interpolate(['color(--ryb 0 0 1)', 'color(--ryb 0 1 0)'], space='ryb') >>> Color.interpolate(['color(--ryb 1 0 0)', 'color(--ryb 0 1 0)'], space='ryb') >>> Color.interpolate(['color(--ryb 1 0 1)', 'color(--ryb 0 1 0)'], space='ryb') ``` ```python >>> Color.interpolate(['color(--ryb 0 0 0)', 'color(--ryb 1 1 1)'], space='ryb') >>> Color.interpolate(['color(--ryb 0 0 1)', 'color(--ryb 1 1 1)'], space='ryb') ``` -------------------------------- ### Initialize and format oRGB colors Source: https://facelessuser.github.io/coloraide/colors/orgb Create oRGB color objects and convert them to string representations. ```python >>> Color("orgb", [0.299, 0.00002, 0.99998]) color(--orgb 0.299 0.00002 0.99998 / 1) >>> Color("orgb", [0.67882, 0.75654, 0.4464]).to_string() 'color(--orgb 0.67882 0.75653 0.4464)' ``` -------------------------------- ### Serialize and Convert Colors to Strings Source: https://facelessuser.github.io/coloraide/strings Demonstrates the difference between to_string and serialize methods regarding gamut mapping. ```python >>> Color("srgb", [0.5, 0, 1.2], 0.3).to_string() 'rgb(120.26 82.191 255 / 0.3)' >>> Color("srgb", [0.5, 0, 1.2], 0.3).serialize() 'rgb(127.5 0 306 / 0.3)' ``` -------------------------------- ### Instantiate and Convert Colors Source: https://facelessuser.github.io/coloraide/plugins/space Create new color instances or convert existing colors using the registered plugin name. ```python Color(NAME, [...]) Color(red).convert(NAME) ``` -------------------------------- ### Generate Color Steps in Different Spaces Source: https://facelessuser.github.io/coloraide/harmonies Demonstrates generating a sequence of colors between black, blue, and white using OkLCh, HSL, and LCh color spaces. ```python >>> Steps(Color.steps(['black', 'blue', 'white'], steps=11, space='oklch')) [color(--oklch 0 0 264.05deg / 1), color(--oklch 0.0904 0.06264 264.05deg / 1), color(--oklch 0.18081 0.12529 264.05deg / 1), color(--oklch 0.27121 0.18793 264.05deg / 1), color(--oklch 0.36161 0.25057 264.05deg / 1), color(--oklch 0.45201 0.31321 264.05deg / 1), color(--oklch 0.56161 0.25057 264.05deg / 1), color(--oklch 0.67121 0.18793 264.05deg / 1), color(--oklch 0.78081 0.12529 264.05deg / 1), color(--oklch 0.8904 0.06264 264.05deg / 1), color(--oklch 1 0 264.05deg / 1)] >>> Steps(Color.steps(['black', 'blue', 'white'], steps=11, space='hsl')) [color(--hsl 240deg 0 0 / 1), color(--hsl 240deg 0.2 0.1 / 1), color(--hsl 240deg 0.4 0.2 / 1), color(--hsl 240deg 0.6 0.3 / 1), color(--hsl 240deg 0.8 0.4 / 1), color(--hsl 240deg 1 0.5 / 1), color(--hsl 240deg 0.8 0.6 / 1), color(--hsl 240deg 0.6 0.7 / 1), color(--hsl 240deg 0.4 0.8 / 1), color(--hsl 240deg 0.2 0.9 / 1), color(--hsl 240deg 0 1 / 1)] >>> Steps(Color.steps(['black', 'blue', 'white'], steps=11, space='lch')) [color(--lch 0 0 301.36deg / 1), color(--lch 5.9137 26.24 301.36deg / 1), color(--lch 11.827 52.481 301.36deg / 1), color(--lch 17.741 78.721 301.36deg / 1), color(--lch 23.655 104.96 301.36deg / 1), color(--lch 29.568 131.2 301.36deg / 1), color(--lch 43.655 104.96 301.36deg / 1), color(--lch 57.741 78.721 301.36deg / 1), color(--lch 71.827 52.481 301.36deg / 1), color(--lch 85.914 26.24 301.36deg / 1), color(--lch 100 0 301.36deg / 1)] ``` -------------------------------- ### ICtCp String Representation Source: https://facelessuser.github.io/coloraide/colors/ictcp Examples of converting ICtCp color objects to various string formats. ```python >>> Color("ictcp", [0.42788, -0.1157, 0.27873]) color(--ictcp 0.42788 -0.1157 0.27873 / 1) >>> Color("ictcp", [0.50498, -0.20797, 0.11073]).to_string() 'ictcp(0.50498 -0.20797 0.11073)' >>> Color("ictcp", [0.56983, -0.25169, 0.03788]).to_string(percent=True) 'ictcp(56.983% -50.338% 7.576%)' >>> Color("ictcp", [0.39138, -0.24061, -0.04423]).to_string(color=True) 'color(--ictcp 0.39138 -0.24061 -0.04423)' ``` -------------------------------- ### Export and Import Colors via Dictionaries Source: https://facelessuser.github.io/coloraide/color Demonstrates basic conversion of a color to a dictionary and back to a Color object. ```python >>> d = Color('purple').to_dict() >>> print(d) {'space': 'srgb', 'coords': [0.5019607843137255, 0.0, 0.5019607843137255], 'alpha': 1.0} >>> Color(d) color(srgb 0.50196 0 0.50196 / 1) ``` -------------------------------- ### Represent HCT Colors Source: https://facelessuser.github.io/coloraide/colors/hct Examples of creating HCT color objects and converting them to string representations. ```python >>> Color("hct", [27.41, 113.36, 53.237], 1) color(--hct 27.41deg 113.36 53.237 / 1) >>> Color("hct", [71.257, 60.528, 74.934], 1).to_string() 'color(--hct 71.257 60.528 74.934)' ``` -------------------------------- ### Demonstrate hue normalization behavior Source: https://facelessuser.github.io/coloraide/about/changelog Shows how ColorAide handles hue values in cylindrical spaces when saturation is zero. ```python >>> Color('hsl(270 0% 50%)') color(--hsl none 0 0.5 / 1) ``` -------------------------------- ### Represent HSLuv colors as strings Source: https://facelessuser.github.io/coloraide/colors/hsluv Examples of string representation and conversion for HSLuv color objects. ```python >>> Color("hsluv", [12.177, 100, 53.237]) color(--hsluv 12.177deg 100 53.237 / 1) >>> Color("hsluv", [44.683, 100, 74.934]).to_string() 'color(--hsluv 44.683 100 74.934)' ``` -------------------------------- ### Represent CAM16 LCD Colors Source: https://facelessuser.github.io/coloraide/colors/cam16_lcd Examples of creating a color object and converting it to a string representation. ```python >>> Color("cam16-lcd", [46.026, 81.254, 27.393], 1) color(--cam16-lcd 46.026 81.254 27.393 / 1) >>> Color("cam16-lcd", [68.056, 43.51, 71.293], 1).to_string() 'color(--cam16-lcd 68.056 43.51 71.293)' ``` -------------------------------- ### Create Discrete Scales with Steps and Methods Source: https://facelessuser.github.io/coloraide/interpolation Uses the steps parameter to define the scale size and a specific interpolation method for the transition. ```python >>> Color.discrete(['red', 'green', 'blue'], steps=5, method='catrom') ``` -------------------------------- ### Represent CAM02-JMh colors in Python Source: https://facelessuser.github.io/coloraide/colors/cam02 Examples of creating color objects and converting them to string representations. ```python >>> Color("cam02-jmh", [46.931, 80.436, 32.157], 1) color(--cam02-jmh 46.931 80.436 32.157deg / 1) >>> Color("cam02-jmh", [68.929, 48.62, 72.359], 1).to_string() 'color(--cam02-jmh 68.929 48.62 72.359)' ``` -------------------------------- ### Mixing Opaque and Transparent Colors Source: https://facelessuser.github.io/coloraide/interpolation Demonstrates how premultiplication affects the influence of colors with different alpha values during a mix operation. ```python >>> Color('orange').mix(Color('blue').set('alpha', 0.25), space='srgb', premultiplied=False) color(srgb 0.5 0.32353 0.5 / 0.625) >>> Color('orange').mix(Color('blue').set('alpha', 0.25), space='srgb') color(srgb 0.8 0.51765 0.2 / 0.625) ``` -------------------------------- ### Importing ColorAide Algebra Source: https://facelessuser.github.io/coloraide/colors/cubehelix Initial setup for using the algebra module within the ColorAide library. ```python >>> from coloraide import algebra as alg ``` -------------------------------- ### Registering a new color space plugin Source: https://facelessuser.github.io/coloraide/color Demonstrates registering a color space plugin to a custom Color class to enable conversion support. ```python >>> from coloraide import Color >>> from coloraide.spaces.xyy import xyY >>> try: ... Color('red').convert('xyy') ... except: ... print('Nope') ... Nope >>> class Custom(Color): ... ... >>> Custom.register(xyY()) >>> Custom('red').convert('xyy') color(--xyy 0.64 0.33 0.21264 / 1) ``` -------------------------------- ### Cubehelix Color Object Usage Source: https://facelessuser.github.io/coloraide/colors/cubehelix Examples of creating Cubehelix color objects and converting them to string representations. ```python >>> Color("cubehelix", [351.81, 1.9489, 0.3]) color(--cubehelix 351.81deg 1.9489 0.3 / 1) >>> Color("cubehelix", [36.577, 1.7357, 0.68176]).to_string() 'color(--cubehelix 36.577 1.7357 0.68176)' ``` -------------------------------- ### Access Labish channels generically Source: https://facelessuser.github.io/coloraide/plugins/space Demonstrates how to use the Labish mix-in to access lightness channels across different color spaces. ```python >>> from coloraide.spaces import Labish >>> srgb = Color('red') >>> jzazbz = srgb.convert('jzazbz') >>> ictcp = srgb.convert('ictcp') >>> for c in (srgb, jzazbz, ictcp): ... if isinstance(c._space, Labish): ... print('color: ', c) ... l = c._space.names()[0] ... print('channel: ', l) ... print('value: ', c.get(l)) ... color: color(--jzazbz 0.13438 0.11789 0.11188 / 1) channel: jz value: 0.13438473104350065 color: color(--ictcp 0.42788 -0.1157 0.27873 / 1) channel: i value: 0.4278802843622844 ``` -------------------------------- ### Create and format HSI colors Source: https://facelessuser.github.io/coloraide/colors/hsi Demonstrates initializing a Color object with HSI coordinates and converting it to a string representation. ```python >>> Color("hsi", [0, 1, 0.33333]) color(--hsi 0deg 1 0.33333 / 1) >>> Color("hsi", [38.824, 1, 0.54902]).to_string() 'color(--hsi 38.824 1 0.54902)' ``` -------------------------------- ### Color String Representation and Conversion Source: https://facelessuser.github.io/coloraide/colors/lch Examples of converting LCh color objects to various string formats. ```python >>> Color("lch", [54.291, 106.84, 40.858]) color(--lch 54.291 106.84 40.858deg / 1) >>> Color("lch", [75.59, 83.769, 70.824]).to_string() 'lch(75.59 83.769 70.824)' >>> Color("lch", [97.607, 94.712, 99.572]).to_string(percent=True) 'lch(97.607% 63.141% 99.572)' >>> Color("lch", [46.278, 67.984, 134.38]).to_string(color=True) 'color(--lch 46.278 67.984 134.38)' ``` -------------------------------- ### Enable Percent Output for color() Source: https://facelessuser.github.io/coloraide/strings Use the percent parameter to format color channels as percentages in the color() function output. ```python >>> Color("rebeccapurple").convert('srgb').to_string(color=True, percent=True) 'color(srgb 40% 20% 60%)' ``` -------------------------------- ### JzCzhz Color Object Manipulation Source: https://facelessuser.github.io/coloraide/colors/jzczhz Examples of creating color objects and converting them to various string formats. ```python >>> Color("jzczhz", [0.13438, 0.16252, 43.502]) color(--jzczhz 0.13438 0.16252 43.502deg / 1) >>> Color("jzczhz", [0.16937, 0.12698, 75.776]).to_string() 'jzczhz(0.16937 0.12698 75.776)' >>> Color("jzczhz", [0.2096, 0.1378, 102]).to_string(percent=True) 'jzczhz(20.96% 53% 102)' >>> Color("jzczhz", [0.09203, 0.10932, 132.99]).to_string(color=True) 'color(--jzczhz 0.09203 0.10932 132.99)' ``` -------------------------------- ### Demonstrating Channel Carrying-Forward Source: https://facelessuser.github.io/coloraide/interpolation Shows how undefined channels are handled when converting between color spaces. ```python >>> rgb = Color('srgb', [0.5, NaN, 0.8]) >>> p3 = rgb.convert('display-p3').set('green', NaN) >>> rgb, p3 (color(srgb 0.5 none 0.8 / 1), color(display-p3 0.45659 none 0.76952 / 1)) ``` -------------------------------- ### Register Jzazbz in Color library Source: https://facelessuser.github.io/coloraide/colors/jzazbz Example of how to manually register the Jzazbz space in a custom Color class. ```python from coloraide import Color as Base from coloraide.spaces.jzazbz.css import Jzazbz class Color(Base): ... Color.register(Jzazbz()) ```