gka / chroma.js

JavaScript library for all kinds of color manipulations
https://gka.github.io/chroma.js/
Other
10.19k stars 546 forks source link

allow computation of weighted average (fixes #231) #233

Closed gka closed 5 years ago

gka commented 5 years ago

adds a new parameter weights to the chroma.average method. weights have to be an array of numbers of the same length as the colors array. weights are normalized automatically.

colors = ['#ddd', 'yellow', 'red', 'teal'];
chroma.average(colors, 'lch'); // unweighted
chroma.average(colors, 'lch', [1,1,2,1]); // more red
chroma.average(colors, 'lch', [1,0.5,1,2.3]); // less yellow, more teal
meodai commented 4 years ago

this is awesome, thanks!