colourFromHue static method

Colour colourFromHue(
  1. double alpha,
  2. double hue,
  3. double chroma,
  4. double secondary,
  5. double match,
)

Constructs a Colour from hue, chroma, secondary component, and match offset values. This is the core algorithm that maps HSL/HSV parameters back to RGB.

Implementation

static Colour colourFromHue(
  double alpha,
  double hue,
  double chroma,
  double secondary,
  double match,
) {
  final (double red, double green, double blue) = switch (hue) {
    < 60.0 => (chroma, secondary, 0.0),
    < 120.0 => (secondary, chroma, 0.0),
    < 180.0 => (0.0, chroma, secondary),
    < 240.0 => (0.0, secondary, chroma),
    < 300.0 => (secondary, 0.0, chroma),
    _ => (chroma, 0.0, secondary),
  };
  return Colour.fromColor(
    Color.fromARGB(
      (alpha * 0xFF).round(),
      ((red + match) * 0xFF).round(),
      ((green + match) * 0xFF).round(),
      ((blue + match) * 0xFF).round(),
    ),
  );
}