Skip to content

Instantly share code, notes, and snippets.

View facelessuser's full-sized avatar
💭
Screaming into the void 😱

Isaac Muse facelessuser

💭
Screaming into the void 😱
View GitHub Profile
@facelessuser
facelessuser / css_l4_gamut.py
Last active February 18, 2022 17:16
CSS Level 4 Gamut mapping
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
@facelessuser
facelessuser / gamut_compare.md
Last active February 16, 2022 18:11
Gamut Comparison

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."""
@facelessuser
facelessuser / okfit.py
Last active January 15, 2022 16:11
Okfit
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"
@facelessuser
facelessuser / playground.md
Last active February 22, 2025 18:08
Page: Coloraide - Playground

Color Notebook

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

@facelessuser
facelessuser / okhsl.py
Last active August 4, 2025 16:15
Okhsl and Okhsv
"""
Okhsl class.
Translation to/from Oklab is licenced under MIT by the original author, all
other code also licensed under MIT: Copyright (c) 2021 Isaac Muse.
---- Oklab license ----
Copyright (c) 2021 Björn Ottosson
@facelessuser
facelessuser / hsluv.py
Last active November 19, 2021 17:43
HSLuv and HPLuv
"""
HSLuv and HPLuv.
Adapted to Python and ColorAide by Isaac Muse (2021)
--- HSLuv Conversion Algorithm ---
Copyright (c) 2012-2021 Alexei Boronine
Copyright (c) 2016 Florian Dormont
@facelessuser
facelessuser / din99o.py
Last active September 8, 2021 17:44
Din99o Lab and Lch
"""
Din99o class.
https://de.wikipedia.org/wiki/DIN99-Farbraum
"""
from coloraide.spaces import RE_DEFAULT_MATCH
from coloraide.spaces.xyz import XYZ
from coloraide.spaces.lch.base import LchBase
from coloraide.spaces.lab.base import LabBase, lab_to_xyz, xyz_to_lab
from coloraide import util
@facelessuser
facelessuser / luv.py
Last active September 15, 2021 18:12
Luv and Lchuv for Coloraide
"""
Luv and Lch class.
https://en.wikipedia.org/wiki/CIELUV
"""
from coloraide.spaces import Space, RE_DEFAULT_MATCH, GamutUnbound, Percent, WHITES, Cylindrical, Angle
from coloraide.spaces.xyz import XYZ
from coloraide import util
from coloraide import Color as ColorOrig
import copy
@facelessuser
facelessuser / pymdownx_shebang.py
Last active April 15, 2021 00:43
Parse shebangs in fences
"""Override default highlighter to handle shebangs."""
import re
RE_SHEBANG = re.compile(r'\A\#!(\w+)\b\s*\r?\n')
def md_shebang(src="", language="", class_name=None, options=None, md="", **kwargs):
"""Formatter wrapper."""
try:
@facelessuser
facelessuser / json_strip.py
Last active April 1, 2019 17:28
json_strip
"""
File Strip.
Licensed under MIT
Copyright (c) 2012 - 2019 Isaac Muse <isaacmuse@gmail.com>
"""
import re
LINE_PRESERVE = re.compile(r"\r?\n", re.MULTILINE)
JSON_COMMENTS_PATTERN = re.compile(