omgovich / colord

👑 A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.63k stars 48 forks source link

Auto-generating palettes using LCH #120

Open galenwinsor opened 8 months ago

galenwinsor commented 8 months ago

Hi! Absolutely love this library. I'm using it to auto generate tones for a color palette from a starting color using lch format. I'm running into issues with the fact that, say, adding 5 to the lightness of a color and then subtracting 5 does not produce the original color (I assume because of the way colord transitions through rgba). I'm wondering if there are currently any workarounds you can think of?

My general approach looks like this:

return shadeIndices.map((n) =>
  colord({ l: l + lightnessTransformation(n), c: c + chromaTransformation(n), ...lch })
);

Where shadeIndices is an array of integers representing tones like [-2, -1, 0, 1, 2]. And lch is the rest of the lch object, doesn't include l and c.

Then, I provide an option to shift the starting lightness up or down.