Construct a Color object from H, S, L values

@param float $h Hue
@param float $s Saturation
@param float $l Lightness

@retuns Color the color object for the HSL values
503589
public static function fromHSL($h, $s, $l)
    {
        // theta plus 360 degrees
        $h -= floor($h);

        $c = new self();

        if ($s == 0) {
            $c->r = $c->g = $c->b = $l * 255;
            return $c;
        }

        $chroma = floatval(1 - abs(2*$l - 1)) * $s;

        // Divide $h by 60 degrees i.e by (60 / 360)
        $h_ = $h * 6;
        // intermediate
        $k = intval($h_);

        $h_mod2 = $k % 2 + $h_ - floor($h_);

        $x = $chroma * abs(1 - abs($h_mod2 - 1));

        $r = $g = $b = 0.0;

        switch ($k) {
        case 0: case 6:
            $r = $chroma;
            $g = $x;
            break;
        case 1:
            $r = $x;
            $g = $chroma;
            break;
        case 2:
            $g = $chroma;
            $b = $x;
            break;
        case 3:
            $g = $x;
            $b = $chroma;
            break;
        case 4:
            $r = $x;
            $b = $chroma;
            break;
        case 5:
            $r = $chroma;
            $b = $x;
            break;
        }

        $m = $l - 0.5 * $chroma;

        $c->r = (($r + $m) * 255);
        $c->g = (($g + $m) * 255);
        $c->b = (($b + $m) * 255);

        return $c;
    }
1183191
private RgbaColor withHsl(int index, float value) {
        float[] HSL = convertToHsl();
        HSL[index] = value;
        return RgbaColor.fromHsl(HSL);
    }
1258258
private static function _hue2rgb( $m1, $m2, $h )
	{
		$h = ( $h < 0 ) ? $h + 1 : ( ( $h > 1 ) ? $h - 1 : $h );
		if ( $h * 6 < 1 ) return $m1 + ( $m2 - $m1 ) * $h * 6;
		if ( $h * 2 < 1 ) return $m2;
		if ( $h * 3 < 2 ) return $m1 + ( $m2 - $m1 ) * ( 0.66666 - $h ) * 6;
		return $m1;
	}
803087
public void setHSV(int hue, int sat, int bri) throws Exception {

        CmsColor color = new CmsColor();
        color.setHSV(hue, sat, bri);

        m_red = color.getRed();
        m_green = color.getGreen();
        m_blue = color.getBlue();
        m_hue = hue;
        m_saturation = sat;
        m_brightness = bri;

        m_tbRed.setText(Integer.toString(m_red));
        m_tbGreen.setText(Integer.toString(m_green));
        m_tbBlue.setText(Integer.toString(m_blue));
        m_tbHue.setText(Integer.toString(m_hue));
        m_tbSaturation.setText(Integer.toString(m_saturation));
        m_tbBrightness.setText(Integer.toString(m_brightness));
        m_tbHexColor.setText(color.getHex());
        setPreview(color.getHex());

        updateSliders();
    }
1274337
def rgb_to_hsl(red, green, blue)
      red = round_rgb_color(red)
      green = round_rgb_color(green)
      blue = round_rgb_color(blue)

      color_max = [red, green, blue].max
      color_min = [red, green, blue].min
      color_range = color_max - color_min
      if color_range == 0
        return [0, 0, (color_max * 100.0 / 255).to_i]
      end
      color_range = color_range.to_f
      hue = (case color_max
             when red then
               HUE_PER_6 * ((green - blue) / color_range)
             when green  then
               HUE_PER_6 * ((blue - red) / color_range) + HUE_PER_6 * 2
             else
               HUE_PER_6 * ((red - green) / color_range) + HUE_PER_6 * 4
             end)

      cnt = color_range / 2.0
      if cnt <= 127
        saturation = color_range / (color_max + color_min) * 100
      else
        saturation = color_range / (510 - color_max - color_min) * 100
      end
      lightness = (color_max + color_min) / 2.0 / 255.0 * 100

      [hue.round, saturation.round, lightness.round]
    end
984342
public static RgbaColor fromHsla(String hsl) {
        String[] parts = getHslaParts(hsl).split(",");
        if (parts.length == 4) {
            float[] HSL = new float[] { parseInt(parts[0]), parseInt(parts[1]), parseInt(parts[2]) };
            RgbaColor ret = fromHsl(HSL);
            if (ret != null) {
                ret.a = parseFloat(parts[3]);
            }
            return ret;
        }
        else {
            return getDefaultColor();
        }
    }
394547
private static function hsl2rgb($h, $s, $l, &$r, &$g, &$b)
    {
        if ($s == 0) {
            $r = round($l * 255);
            $g = $r;
            $b = $r;

            return;
        }

        $temp1;
        if ($l < 0.5) {
            $temp1 = $l * (1.0 + $s);
        } else {
            $temp1 = $l + $s - $l * $s;
        }

        $temp2 = 2 * $l - $temp1;

        $h = $h / 360;

        $tempR = $h + (1 / 3);
        $tempG = $h;
        $tempB = $h - (1 / 3);

        if ($tempR < 0) {
            $tempR++;
        } elseif ($tempR > 1) {
            $tempR--;
        }

        if ($tempG < 0) {
            $tempG++;
        } elseif ($tempG > 1) {
            $tempG--;
        }

        if ($tempB < 0) {
            $tempB++;
        } elseif ($tempB > 1) {
            $tempB--;
        }

        if (6 * $tempR < 1) {
            $r = $temp2 + ($temp1 - $temp2) * 6 * $tempR;
        } elseif (2 * $tempR < 1) {
            $r = $temp1;
        } elseif (3 * $tempR < 2) {
            $r = $temp2 + ($temp1 - $temp2) * ((2 / 3) - $tempR) * 6;
        } else {
            $r = $temp2;
        }

        if (6 * $tempG < 1) {
            $g = $temp2 + ($temp1 - $temp2) * 6 * $tempG;
        } elseif (2 * $tempG < 1) {
            $g = $temp1;
        } elseif (3 * $tempG < 2) {
            $g = $temp2 + ($temp1 - $temp2) * ((2 / 3) - $tempG) * 6;
        } else {
            $g = $temp2;
        }

        if (6 * $tempB < 1) {
            $b = $temp2 + ($temp1 - $temp2) * 6 * $tempB;
        } elseif (2 * $tempB < 1) {
            $b = $temp1;
        } elseif (3 * $tempB < 2) {
            $b = $temp2 + ($temp1 - $temp2) * ((2 / 3) - $tempB) * 6;
        } else {
            $b = $temp2;
        }

        $r = round($r * 255);
        $g = round($g * 255);
        $b = round($b * 255);
    }
1137957
public static int fromHSL(float h, float s, float l) {
        int alpha = MAX_INT;
        return fromHSL(h, s, l, alpha);
    }
843609
function rgbaToHsla(h, s, l, a) {
  return [...rgbToHsl(h,s,l), a];
}
986037
def get_hs_color(self):
        
        # Get the color from homematic. In general this is just the hue parameter.
        hm_color = self.getCachedOrUpdatedValue("COLOR", channel=self._color_channel)

        if hm_color >= 200:
            # 200 is a special case (white), so we have a saturation of 0.
            # Larger values are undefined. For the sake of robustness we return "white" anyway.
            return 0, 0

        # For all other colors we assume saturation of 1
        return hm_color/200, 1
279484
def hsl_to_rgb(self, h, s, l):
        

        h = h % 1.0
        s = min(max(s, 0.0), 1.0)
        l = min(max(l, 0.0), 1.0)

        if l <= 0.5:
            m2 = l*(s + 1.0)
        else:
            m2 = l + s - l*s
        m1 = l*2.0 - m2
        r = self._hue_to_rgb(m1, m2, h + 1.0/3.0)
        g = self._hue_to_rgb(m1, m2, h)
        b = self._hue_to_rgb(m1, m2, h - 1.0/3.0)

        # Apply gamma correction
        r **= self.gamma
        g **= self.gamma
        b **= self.gamma

        return (r, g, b)
348711
@Nonnull
  @Nonempty
  public static String getHSLColorValue (final float fHue, final float fSaturation, final float fLightness)
  {
    return new StringBuilder (18).append (CCSSValue.PREFIX_HSL_OPEN)
                                 .append (getHSLHueValue (fHue))
                                 .append (',')
                                 .append (getHSLPercentageValue (fSaturation))
                                 .append ("%,")
                                 .append (getHSLPercentageValue (fLightness))
                                 .append ("%")
                                 .append (CCSSValue.SUFFIX_HSL_CLOSE)
                                 .toString ();
  }
513630
def mix!(other, pct = 50.0)
      coeff = pct.to_f / 100.0
      new_rgb = to_rgb.zip(other.to_rgb).map{|c1, c2| (c1 * (1 - coeff)) + (c2 * coeff)}
      h, s, l = self.class.rgb_to_hsl(*new_rgb)
      self.hue, self.saturation, self.lightness = 360*h, s, l
    end
1207482
public static function hslToRgb($h, $s, $l)
    {
        if (\min($h, $s, $l) < 0) {
            throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0');
        }

        if ($h > 360 || \max($s, $l) > 100) {
            throw new InvalidArgumentException('The parameters for hslToRgb should be no more than 360, 100, and 100 respectively');
        }

        $h /= 360;
        $s /= 100;
        $l /= 100;

        $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s;
        $m1 = $l * 2 - $m2;

        return array(
            (int) \round(self::hueToRgb($m1, $m2, $h + 1 / 3) * 0xFF),
            (int) \round(self::hueToRgb($m1, $m2, $h) * 0xFF),
            (int) \round(self::hueToRgb($m1, $m2, $h - 1 / 3) * 0xFF),
        );
    }
682130
@SuppressWarnings("squid:S1244")
    public HSL getHSL() {
        // Convert the RGB values to the range 0-1
        double red = r / 255.0;
        double green = g / 255.0;
        double blue = b / 255.0;

        // Find the minimum and maximum values of R, G and B.
        double min = Math.min(red, Math.min(green, blue));
        double max = Math.max(red, Math.max(green, blue));
        double delta = max - min;

        // Now calculate the luminace value by adding the max and min values and divide by 2.
        double l = (min + max) / 2;

        // The next step is to find the Saturation.
        double s = 0;

        // If the min and max value are the same, it means that there is no saturation.
        // If all RGB values are equal you have a shade of grey.
        if (Math.abs(delta) > EPSILON) {
            // Now we know that there is Saturation we need to do check the level of the Luminance
            // in order to select the correct formula.
            if (l < 0.5) {
                s = delta / (max + min);
            } else {
                s = delta / (2.0 - max - min);
            }
        }

        // The Hue formula is depending on what RGB color channel is the max value.
        double h = 0;
        if (delta > 0) {
            if (red == max) {
                h = (green - blue) / delta;
            } else if (green == max) {
                h = ((blue - red) / delta) + 2.0;
            } else {
                h = ((red - green) / delta) + 4.0;
            }
        }

        // The Hue value you get needs to be multiplied by 60 to convert it to degrees on the color circle
        // If Hue becomes negative you need to add 360 to, because a circle has 360 degrees.
        h = h * 60;

        return new HSL((int) Math.round(h), s, l);
    }
56650
def _hue(color, **kwargs):
    
    h = colorsys.rgb_to_hls(*[x / 255.0 for x in color.value[:3]])[0]
    return NumberValue(h * 360.0)
834809
public function toHSL($red, $green, $blue)
    {
        $min = min($red, $green, $blue);
        $max = max($red, $green, $blue);

        $l = $min + $max;
        $d = $max - $min;

        if ((int) $d === 0) {
            $h = $s = 0;
        } else {
            if ($l < 255) {
                $s = $d / $l;
            } else {
                $s = $d / (510 - $l);
            }

            if ($red == $max) {
                $h = 60 * ($green - $blue) / $d;
            } elseif ($green == $max) {
                $h = 60 * ($blue - $red) / $d + 120;
            } elseif ($blue == $max) {
                $h = 60 * ($red - $green) / $d + 240;
            }
        }

        return [Type::T_HSL, fmod($h, 360), $s * 100, $l / 5.1];
    }