This implements the gamut mapping algorithm according to CSS Level 4 specification.
from coloraide.gamut import Fit
from coloraide.util import NaN
class OklchChroma(Fit):
"""Lch chroma gamut mapping class."""
inputs = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] | |
colors = Color.steps(inputs, steps=10, space='srgb') | |
HtmlRow(colors) | |
HtmlRow([c.filter('brightness', 0.5).clip() for c in colors]) | |
HtmlRow([c.filter('saturate', 0.5).clip() for c in colors]) | |
HtmlRow([c.filter('contrast', 1.2).clip() for c in colors]) | |
HtmlRow([c.filter('opacity', 0.5).clip() for c in colors]) | |
HtmlRow([c.filter('invert', 1).clip() for c in colors]) | |
HtmlRow([c.filter('hue-rotate', 90).clip() for c in colors]) | |
HtmlRow([c.filter('sepia', 1).clip() for c in colors]) |
"""CAM16 class.""" | |
import math | |
from coloraide.spaces import Space, Labish | |
from coloraide.distance import DeltaE | |
from coloraide.cat import WHITES | |
from coloraide.channels import Channel, FLG_ANGLE | |
from coloraide import util | |
from coloraide import algebra as alg | |
from coloraide.types import Vector, VectorLike | |
from typing import Optional |
from coloraide.contrast import ColorContrast | |
class Weber(ColorContrast): | |
"""Weber contrast.""" | |
NAME = "weber" | |
@classmethod | |
def contrast(cls, color1, color2, **kwargs): | |
"""Contrast.""" |
inputs = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] | |
colors = Color(inputs[0]).steps(inputs[1:], steps=20, space='srgb') | |
colors | |
ColorRow() | |
[c.cvd('achromatopsia').clip() for c in colors] | |
ColorRow() | |
[c.cvd('brettel-protan').clip() for c in colors] | |
ColorRow() | |
[c.cvd('brettel-deutan').clip() for c in colors] | |
ColorRow() |
from coloraide.gamut import Fit, clip_channels | |
from coloraide.util import NaN | |
class OklchChroma(Fit): | |
"""Lch chroma gamut mapping class.""" | |
NAME = "oklch-chroma" | |
EPSILON = 0.0001 |
print('---- Gamut Mapping with Oklch ----') | |
class Color2(Color): | |
FIT = "oklch-chroma" | |
colors = ['green', 'blue'] | |
Color2.interpolate(colors, space="lab") | |
Color2.interpolate(colors, space="lch") | |
Color2.interpolate(colors, space="oklab") | |
Color2.interpolate(colors, space="oklch") | |
print('---- Gamut Mapping with CIE LCH ----') |
from coloraide.gamut import Fit, clip_channels | |
from coloraide.util import NaN | |
class OklchChroma(Fit): | |
"""Lch chroma gamut mapping class.""" | |
NAME = "oklch-chroma" | |
EPSILON = 0.0001 |
This implements the gamut mapping algorithm according to CSS Level 4 specification.
from coloraide.gamut import Fit
from coloraide.util import NaN
class OklchChroma(Fit):
"""Lch chroma gamut mapping class."""
from coloraide.distance.delta_e_76 import DE76 | |
from coloraide.gamut.fit_lch_chroma import LchChroma | |
from coloraide import Color as OrigColor | |
class DEOK(DE76): | |
"""Delta E OK class.""" | |
NAME = "ok" | |
SPACE = "oklab" |
ColorAide's documentation is rendered with Python Markdown and Pymdown Extensions. The color notebook implements a dynamic, live environment allowing for on the fly page rendering and interactive Python code examples with beautiful visualization of color. This is accomplished by using Pyodide to execute the required Python modules to render the desired pages.
Though Pyodide is used to run the Python code, the actual code is handled special so that we can intercept color objects at various times and translate them to color swatches and gradients. Because of this, asynchrounous code is not really handled