Skip to content

Output of mix function from TinyColor is not right #6

@salkuadrat

Description

@salkuadrat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions