omgovich / colord

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

Improvement: mix many colors at once #73

Closed EricRovell closed 3 years ago

EricRovell commented 3 years ago

I have reimplemented mix plugin in my project by studying your code. API seems so fine and simple thanks to CIE LAB color space. But I was thinking that I would be very nice to have an ability to mix many colors at once.

Right now I have got two possible scenarios: as new method or separate function just like random() utility. I think it would be fine to use an array of objects as arguments:

interface MixtureIngridient {
  color: Colord | Input;
  ratio: number;
}

mix(colors: MixtureIngridients[]);

But I am not sure what is better option. Am I right that if we implement the utility function approach it should be as separate bundle? And how it is better to implement this size-efficiently? Right now I do not have any idea, if you like the idea of mixing several colors I need some help with correct architecture.

omgovich commented 3 years ago

Hi @EricRovell! How are you?

It seems to me that mixing more than two colors is a pretty rare task (I have never had to do that in 13 years of frontend development).

I refer to CSS specs when I experience some doubt in ideas. CSS also contains a color-mixing method, and it mixes two colors — so I can assume that there is no need for a more powerful color mixing method — people who are smarter than me have already investigated the issue and realized mixing two colors is sufficient. https://www.w3.org/TR/css-color-5/#funcdef-color-mix

omgovich commented 3 years ago

Also, don't forget that people can use chaining like

colord('blue').mix('red').mix('black') // dark purple
EricRovell commented 3 years ago

I see, I guess it is not worth the time then. Thank you for explanation, I will close the issue then! 🤔