Cubehelix.from constructor
Cubehelix.from(
- Object? source
Creates an instance of Cubehelix color by converting the specified
source
object.
If a CSS Color Module Level 3 specifier string is specified, it is parsed and then converted to the Cubehelix color space. See Color.parse for examples. If a color instance is specified, it is converted to the RGB color space using Color.rgb and then converted to Cubehelix. (Colors already in the Cubehelix color space skip the conversion to RGB.)
Implementation
factory Cubehelix.from(Object? source) {
if (source is Cubehelix) return source.copy();
if (source is! Rgb) source = Rgb.from(source);
var r = source.r / 255,
g = source.g / 255,
b = source.b / 255,
l = (_bcda * b + _ed * r - _eb * g) / (_bcda + _ed - _eb),
bl = b - l,
k = (_e * (g - l) - _c * bl) / _d,
s = sqrt(k * k + bl * bl) / (_e * l * (1 - l)), // NaN if l=0 or l=1
h = !s.isNaN ? atan2(k, bl) * degrees - 120 : double.nan;
return Cubehelix(h < 0 ? h + 360 : h, s, l, source.opacity);
}