hslToRgb method

void hslToRgb (Vector4 hslColor, Vector4 rgbColor)

Convert hslColor from hue, saturation, and lightness (HSL) color model to the RGB color model and store it in rgbColor.

Implementation

static void hslToRgb(Vector4 hslColor, Vector4 rgbColor) {
  if (hslColor.y == 0.0) {
    rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a);
  } else {
    final double q = hslColor.z < 0.5
        ? hslColor.z * (1.0 + hslColor.y)
        : hslColor.z + hslColor.y - hslColor.z * hslColor.y;
    final double p = 2.0 * hslColor.z - q;

    final double r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0);
    final double g = _hueToRgb(p, q, hslColor.x);
    final double b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0);

    rgbColor.setValues(r, g, b, hslColor.a);
  }
}