Пример #1
0
 public function testRgbToHsl()
 {
     $tests = ['#FEF888' => [57, 98, 76], '#19CB97' => [162, 78, 45], '#362698' => [248, 60, 37], '#FFFFFF' => [0, 0, 100], '#000000' => [0, 0, 0]];
     foreach ($tests as $rgb => $values) {
         $c = \Colourist\Colour::fromHex($rgb)->toHsl();
         $this->assertSame($values[0], $c->hue());
         $this->assertSame($values[1], $c->saturation());
         $this->assertSame($values[2], $c->lightness());
     }
 }
Пример #2
0
 /**
  * Create a new RGB from the given red, green and blue channels.
  *
  * @param float $hue
  *   Hue is a value between 0 and 360 representing the hue of this colour. If
  *   a number outside this range is provided it will be wrapped to fit inside
  *   this range.
  * @param float $saturation
  *   Saturation of this colour.
  * @param float $lightness
  *   Lightness of this colour.
  * @param Colour $original
  *   A colour that this was transformed from.
  */
 public function __construct($hue, $saturation, $lightness, Colour $original = NULL)
 {
     v::numeric()->assert($hue);
     Colour::validatePercentage($saturation);
     Colour::validatePercentage($lightness);
     $this->hue = self::bcfmod($hue, 360, self::$bcscale);
     if ($this->hue < 0) {
         $this->hue = bcadd($this->hue, 360, self::$bcscale);
     }
     $this->saturation = bcdiv($saturation, 100, self::$bcscale);
     $this->lightness = bcdiv($lightness, 100, self::$bcscale);
     $this->chroma = bcmul($this->saturation, bcsub(1, abs(bcmul(2, $this->lightness, self::$bcscale) - 1), self::$bcscale), self::$bcscale);
     $this->hsl = $this;
     if (isset($original)) {
         $this->rgb = $original->rgb;
         $this->hsb = $original->hsb;
     }
 }
Пример #3
0
 /**
  * @expectedException \Respect\Validation\Exceptions\AllOfException
  */
 public function testFromHexBadCode()
 {
     \Colourist\Colour::fromHex('oops, this is bad');
 }