Output of mix function from TinyColor is not right
salkuadrat opened this issue · 0 comments
I try to use TinyColor to create custom color swatch.
But when I try to mix colors with different amount, such as 20, 30, 40, 50, some of them return the same output.
Then I check to the original mix at tinycolor.js. It seems like you use rounded integer value of p:
final int p = (amount / 100).round(); (line 146 at tinycolor.dart)
when originally it should not be rounded, like:
var p = amount / 100; (line 707 at tinycolor.js)
or when convert to dart:
final double p = amount / 100;
I think the value that need to be rounded is after multiply with p:
final double p = amount / 100;
final color = Color.fromARGB(
((input.alpha - _color.alpha) * p).round() + _color.alpha,
((input.red - _color.red) * p).round() + _color.red,
((input.green - _color.green) * p).round() + _color.green,
((input.blue - _color.blue) * p).round() + _color.blue);
return TinyColor(color);