Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output of mix function from TinyColor is not right #6

Open
salkuadrat opened this issue Sep 24, 2020 · 0 comments
Open

Output of mix function from TinyColor is not right #6

salkuadrat opened this issue Sep 24, 2020 · 0 comments

Comments

@salkuadrat
Copy link

salkuadrat commented Sep 24, 2020

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);

calvintam236 referenced this issue in TinyCommunity/tinycolor2 Jun 25, 2021
Fixes issues #2, #6, and #10 on FooStudio/tinycolor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant