hsv2rgb static method

List<int> hsv2rgb(
  1. num hue,
  2. num saturation,
  3. num valueBrightness
)

Implementation

static List<int> hsv2rgb(num hue, num saturation, num valueBrightness) {
  if (saturation <= 1 && valueBrightness <= 1) {
    // if both <=1 we assume that are 0-1 range, NOTE that means if REALLT want (0.01 s then you need to pass it like that and not as 1 in to 100 scale)
    saturation *= 100;
    valueBrightness *= 100;
  }
  hue = hue / 60;
  saturation = saturation / 100;
  valueBrightness = valueBrightness / 100;
  var hi = hue.floor() % 6;

  var f = hue - hue.floor();
  int p = (255 * valueBrightness * (1 - saturation)).round();
  int q = (255 * valueBrightness * (1 - (saturation * f))).round();
  int t = (255 * valueBrightness * (1 - (saturation * (1 - f)))).round();
  int iV = (255 * valueBrightness).round();

  switch (hi) {
    case 0:
      return [iV, t, p];
    case 1:
      return [q, iV, p];
    case 2:
      return [p, iV, t];
    case 3:
      return [p, q, iV];
    case 4:
      return [t, p, iV];
    case 5:
    default:
      return [iV, p, q];
  }
}