Convert HSL to RGB

@access protected
@param  integer  $hue         Hue ∈ [0, 360)
@param  integer  $saturation  Saturation ∈ [0, 1]
@param  integer  $lightness   Lightness ∈ [0, 1]
@return array
168981
protected function HSL2RGB($H, $S, $L) {
        $H /= 360;
        $q = $L < 0.5 ? $L * (1 + $S) : $L + $S - $L * $S;
        $p = 2 * $L - $q;

        return array_map(function ($color) use ($q, $p) {
            if ($color < 0) {
                $color++;
            }
            if ($color > 1) {
                $color--;
            }
            if ($color < 1/6) {
                $color = $p + ($q - $p) * 6 * $color;
            } else if ($color < 0.5) {
                $color = $q;
            } else if ($color < 2/3) {
                $color = $p + ($q - $p) * 6 * (2/3 - $color);
            } else {
                $color = $p;
            }
            return round($color * 255);
        }, array($H + 1/3, $H, $H - 1/3));
    }
399136
public function toHSL()
    {
        return [
            round($this->hue),
            round($this->saturation),
            round($this->lightness),
        ];
    }
995097
protected function getColorScore($color, $count, $colorsCount)
	    {
	        $sRGBComponents = $this->getSRGBComponents($this->getRGBComponents($color));
	        $max 			= max($sRGBComponents);
	        $min 			= min($sRGBComponents);
	        $diff 			= $max - $min;
	        $sum 			= $max + $min;
	        $saturation 	= $diff ? ($sum / 2 > .5 ? $diff / (2 - $diff) : $diff / $sum) : 0;
	        $luminosity 	= ($sum / 2 + .2126 * $sRGBComponents[0] + .7152 * $sRGBComponents[1] + .0722 * $sRGBComponents[2]) / 2;

	        return $saturation < .5 ?
	            (1 - $luminosity) * $count / $colorsCount :
	            $count * ($saturation) * $luminosity;
	    }
168826
public void setColorByHSL(float hue, float saturation, float lightness) {
		float[] arithmeticRGB = ColorUtils.toArithmeticRGB(hue, saturation,
				lightness);
		setRed(arithmeticRGB[0]);
		setGreen(arithmeticRGB[1]);
		setBlue(arithmeticRGB[2]);
	}
1001184
public static function rgbToHsl($r, $g, $b)
    {
        $r /= 255;
        $g /= 255;
        $b /= 255;
        $max = max($r, $g, $b);
        $min = min($r, $g, $b);
        $h = 0;
        $l = ($max + $min) / 2;
        $d = $max - $min;

        if ($d == 0) {
            $h = $s = 0; // achromatic
        } else {
            $s = (1 - abs(2 * $l - 1));
            switch ($max) {
                case $r:
                    $h = 60 * fmod((($g - $b) / $d), 6);
                    if ($b > $g) {
                        $h += 360;
                    }
                    break;
                case $g:
                    $h = 60 * (($b - $r) / $d + 2);
                    break;
                case $b:
                    $h = 60 * (($r - $g) / $d + 4);
                    break;
            }
        }

        return array(round($h, 2), round($s, 2), round($l, 2));
    }
184515
private static function rgb($color) {

		return (object) [

			'r' => intval(hexdec(substr($color, 0, 2))),
			'g' => intval(hexdec(substr($color, 2, 2))),
			'b' => intval(hexdec(substr($color, 4, 2)))
		];
	}
342383
public static function rgb2hsv( $rgb )
	{
#		return self::rgb2hsv_2( $rgb );
		list( $r, $g, $b ) = $rgb;
		$v	= max( $r, $g, $b );
		$t	= min( $r, $g, $b );
		$s	= ( $v == 0 ) ? 0 : ( $v - $t ) / $v;
		if( $s == 0 )
			$h	= 0;
		else
		{
			$a	= $v - $t;
			$cr	= ( $v - $r ) / $a;
			$cg	= ( $v - $g ) / $a;
			$cb	= ( $v - $b ) / $a;
			$h	= ( $r == $v ) ? $cb - $cg : ( ( $g == $v ) ? 2 + $cr - $cb : ( ( $b == $v ) ? $h = 4 + $cg - $cr : 0 ) );
			$h	= 60 * $h;
			$h	= ( $h < 0 ) ? $h + 360 : $h;
		}
		return array( round( $h ), round( $s * 100 ), round( $v / 2.55 ) );
	}
258787
private static final double[] getRGB(double hue, double saturation, double brightness) {
        double[] rgb = {0.0, 0.0, 0.0};

        double tmpHue = hue * 360.0;
        int hi;
        double f;
        double p, q, t;

        hi = (int)Math.floor(tmpHue / 60.0) % 6;
        f  = tmpHue / 60.0 - hi;
        p  = (brightness * (1.0 - saturation));
        q  = (brightness * (1.0 - saturation * f));
        t  = (brightness * (1.0 - saturation * (1.0 - f)));

        switch (hi) {
        case 0:
            rgb[0] = brightness;
            rgb[1] = t;
            rgb[2] = p;
            break;
        case 1:
            rgb[0] = q;
            rgb[1] = brightness;
            rgb[2] = p;
            break;
        case 2:
            rgb[0] = p;
            rgb[1] = brightness;
            rgb[2] = t;
            break;
        case 3:
            rgb[0] = p;
            rgb[1] = q;
            rgb[2] = brightness;
            break;
        case 4:
            rgb[0] = t;
            rgb[1] = p;
            rgb[2] = brightness;
            break;
        case 5:
            rgb[0] = brightness;
            rgb[1] = p;
            rgb[2] = q;
            break;
        default:
            break;
        }

        return rgb;
    }
441213
public static function hsl(Color $color)
    {
        $hsl = $color->getHsl();

        return sprintf(
            'hsl(%s, %s%%, %s%%)',
            sprintf('%0.1f', $hsl['h'] * 360) + 0,
            sprintf('%0.1f', $hsl['s'] * 100) + 0,
            sprintf('%0.1f', $hsl['l'] * 100) + 0
        );
    }
759925
public static final Color fromHSL(double h, double s, double l)
    {
        h = (((h % 360) + 360) % 360) / 360;

        s = convertPercents(s);

        l = convertPercents(l);

        return fromNormalizedHSL(h, s, l);
    }
49842
public function toHex()
    {
        $H = $this->values['hue'] / 360;
        $S = $this->values['saturation'];
        $L = $this->values['lightness'];

        if ($S == 0) {
            $r = $L * 255;
            $g = $L * 255;
            $b = $L * 255;
        } else {
            $var_2 = ($L < 0.5) ?  $L * (1 + $S) : ($L + $S) - ($S * $L);

            $var_1 = 2 * $L - $var_2;

            $r = round(255 * $this->hueToRgb($var_1, $var_2, $H + (1 / 3)));
            $g = round(255 * $this->hueToRgb($var_1, $var_2, $H));
            $b = round(255 * $this->hueToRgb($var_1, $var_2, $H - (1 / 3)));
        }

        $hex = array(
            dechex($r),
            dechex($g),
            dechex($b)
        );

        //Make sure the hex is 6 digit
        foreach ($hex as $key => $value) {
            $hex[$key] = strlen($value) === 1 ? '0' . $value : $value ;
        }

        return implode('', $hex);
    }
790265
function (hue, saturation, value) {
      var rgb = hsb2rgb(hue, saturation, value);
      return 'rgb(' + rgb.join(', ') + ')';
    }
843609
function rgbaToHsla(h, s, l, a) {
  return [...rgbToHsl(h,s,l), a];
}
1258124
def weight_color_hsl(weight, weight_range, min_lightness=0.8):
    # type: (float, float, float) -> _HSL_COLOR
    
    hue = _hue(weight)
    saturation = 1
    rel_weight = (abs(weight) / weight_range) ** 0.7
    lightness = 1.0 - (1 - min_lightness) * rel_weight
    return hue, saturation, lightness
773147
public function hsl2rgb($h, $s, $l)
	{
		if ($s == 0) {
			$r = $l * 255;
			$g = $l * 255;
			$b = $l * 255;
		} else {
			if ($l < 0.5) {
				$tmp = $l * (1 + $s);
			} else {
				$tmp = ($l + $s) - ($s * $l);
			}
			$tmp2 = 2 * $l - $tmp;
			$r = round(255 * $this->hue2rgb($tmp2, $tmp, $h + (1 / 3)));
			$g = round(255 * $this->hue2rgb($tmp2, $tmp, $h));
			$b = round(255 * $this->hue2rgb($tmp2, $tmp, $h - (1 / 3)));
		}

		return [$r, $g, $b];
	}
289239
private function hue2rgb($v1, $v2, $hue)
		{
		if ($hue < 0)
			{
			$hue += 1;
			}
		if ($hue > 1)
			{
			$hue -= 1;
			}
		if ((6 * $hue) < 1)
			{
			return ($v1 + ($v2 - $v1) * 6 * $hue);
			}
		if ((2 * $hue) < 1)
			{
			return ($v2);
			}
		if ((3 * $hue) < 2)
			{
			return ($v1 + ($v2 - $v1) * (( 2 / 3) - $hue) * 6);
			}
		return $v1;
		}
891557
private static function _get_hue( $hex ) {
		$red   = hexdec( substr( $hex, 0, 2 ) );
		$green = hexdec( substr( $hex, 2, 2 ) );
		$blue  = hexdec( substr( $hex, 4, 2 ) );

		if ( $red === $green && $red === $blue ) {
			return 0;
		}

		$hue = static::_get_hue_based_max_rgb( $red, $green, $blue );

		if ( 0 > $hue ) {
			$hue += 360;
		}

		return $hue;
	}