SassColour::hsl2rgb PHP Метод

hsl2rgb() публичный Метод

Converts from HSL to RGB colourspace Algorithm from the CSS3 spec: {@link http://www.w3.org/TR/css3-color/#hsl-color}
public hsl2rgb ( )
    public function hsl2rgb()
    {
        $h = $this->getHue(true) / 360;
        $s = $this->getSaturation(true) / 100;
        $l = $this->getLightness(true) / 100;
        $q = $l < 0.5 ? $l * (1 + $s) : $l + $s - $l * $s;
        $p = 2 * $l - $q;
        $this->red = $this->hue2rgb($p, $q, $h + 1 / 3);
        $this->green = $this->hue2rgb($p, $q, $h);
        $this->blue = $this->hue2rgb($p, $q, $h - 1 / 3);
    }

Usage Example

Пример #1
0
 /**
  * Scales one or more property of the color by the percentage requested.
  *
  * @param SassColour $color the colour to adjust
  * @param int        $red
  * @param int        $green
  * @param int        $blue
  * @param int        $saturation
  * @param int        $lightness
  * @param int        $alpha
  *
  * @internal param $SassNumber (red, green, blue, saturation, lightness, alpha) - the amount(s) to scale by
  * @return SassColour
  */
 public static function scale_color($color, $red = 0, $green = 0, $blue = 0, $saturation = 0, $lightness = 0, $alpha = 0)
 {
     $maxes = array('red' => 255, 'green' => 255, 'blue' => 255, 'saturation' => 100, 'lightness' => 100, 'alpha' => 1);
     $color->rgb2hsl();
     foreach ($maxes as $property => $max) {
         $obj = ${$property};
         $scale = 0.01 * $obj->value;
         $diff = $scale > 0 ? $max - $color->{$property} : $color->{$property};
         $color->{$property} = $color->{$property} + $diff * $scale;
     }
     $color->hsl2rgb();
     return $color;
 }