Adding HSLColor and color 'within' matchers for HSVColor and HSLColor (#18294)

This adds an HSLColor class which uses a perceptual color space based upon human perception of colored light (as opposed to HSV, which is based on pigment colors).

You can see the difference in the color spaces here: https://en.wikipedia.org/wiki/HSL_and_HSV

I also added a "within" matcher for both HSLColor and HSVColor that will check if the (floating point) color components are within a certain error.

And tests.
This commit is contained in:
Greg Spencer
2018-06-18 17:11:42 -07:00
committed by GitHub
parent bd4cf62821
commit efa2a474ea
4 changed files with 697 additions and 85 deletions

View File

@@ -167,7 +167,7 @@ class _ChipDemoState extends State<ChipDemo> {
Color _nameToColor(String name) {
assert(name.length > 1);
final int hash = name.hashCode & 0xffff;
final double hue = 360.0 * hash / (1 << 15);
final double hue = (360.0 * hash / (1 << 15)) % 360.0;
return new HSVColor.fromAHSV(1.0, hue, 0.4, 0.90).toColor();
}