fromRGB static method
Implementation
static HSL fromRGB(double r, double g, double b) {
final double rBound = _bound(r, 255.0);
final double gBound = _bound(g, 255.0);
final double bBound = _bound(b, 255.0);
final max = [rBound, gBound, bBound].reduce(math.max);
final min = [rBound, gBound, bBound].reduce(math.min);
double h = 0.0;
double s = 0.0;
final double l = (max + min) / 2;
if (max == min) {
h = s = 0.0;
} else {
final double d = max - min;
s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min);
if (max == rBound) {
h = (gBound - bBound) / d + (gBound < bBound ? 6 : 0);
} else if (max == gBound) {
h = (bBound - rBound) / d + 2;
} else if (max == bBound) {
h = (rBound - gBound) / d + 4;
}
}
h /= 6.0;
return HSL(h, s, l);
}