Skip to content

Instantly share code, notes, and snippets.

@StephenHaney
StephenHaney / find-max-chroma-per-hue-oklch.ts
Last active December 14, 2024 07:11
Maximum possible chroma for a given hue in OKLCH, 3 ways with performance benchmark
import { clampChroma } from 'culori';
const PHI = (1 + Math.sqrt(5)) / 2; // Golden ratio
const PRECISION = 0.002;
function findMaxChroma(hue: number) {
let a = 0;
let b = 1;
let c = b - (b - a) / PHI;