Closed patrikengborg closed 2 years ago
Hi! In the modern JavaScript you don't need methods like set
: you can just build a new color using destructurisation:
const oldHsl = color.toHsl()
colord({ ...hsl, l: 20 })
Ok cool, for some reason I didn't think of that obvious solution, thanks.
What about modifying LCH colors.. I don't think I can just change the L value there, since a lightness change also involves the other channels in the color, if I understand LCH correctly, right?
So is there any way to change a LCH color to an absolute lightness value of 5%, without doing it relatively with lighten() or darken() ?
Sorry if this is a weird question or out of place. I'm currently trying to grasp LCH and how it works.
You can do the same with LCH color if lch
plugin is enabled:
import { colord, extend } from "colord";
import lchPlugin from "colord/plugins/lch";
extend([lchPlugin]);
const oldLch = colord({ l: 50, c: 0, h: 0 }).toLch()
colord({ ...oldLch, l: 100 }).toLch() // { l: 100, c: 0, h: 0, a: 1 }
colord's parser detects a color model automatically (based on the object fields).
If an input object has l
, c
and h
keys the parser consider the values as LCH.
Thanks, I'll give it a try!
Hi,
This seems like an awesome library! I'm using Chroma.js right now, but I'm tempted to switch.
One thing I use in Chroma all the time is the
color.set()
function. It lets you change a single channel in a color, like:chroma('#036').set('hsl.l', 0.2).hex();
It's not a relative modification like
lighten()
anddarken()
i Colord.Is there an equivalent for
color.set()
in Colord?