Ejemplo n.º 1
0
 /**
  * Operations have to be done per-channel, if not,
  * channels will spill onto each other. Once we have
  * our result, in the form of an integer triplet,
  * we create a new color node to hold the result.
  *
  * @param ILess_Environment $env
  * @param string $op
  * @param ILess_Node $other
  * @return ILess_Node_Color
  * @throws InvalidArgumentException
  */
 public function operate(ILess_Environment $env, $op, ILess_Node $other)
 {
     $result = array();
     if (!$other instanceof ILess_Node_Color) {
         if (!self::methodExists($other, 'toColor')) {
             throw new InvalidArgumentException('The other node must implement toColor() method to operate');
         }
         $other = $other->toColor();
         if (!$other instanceof ILess_Node_Color) {
             throw new InvalidArgumentException('The toColor() method must return an instance of ILess_Node_Color');
         }
     }
     $t = $this->getRGB();
     $o = $other->getRGB();
     for ($c = 0; $c < 3; $c++) {
         $result[$c] = ILess_Math::operate($op, $t[$c], $o[$c]);
         if ($result[$c] > 255) {
             $result[$c] = 255;
         } elseif ($result < 0) {
             $result[$c] = 0;
         }
     }
     return new ILess_Node_Color($result, $this->color->getAlpha() + $other->color->getAlpha());
 }
Ejemplo n.º 2
0
 /**
  * @covers getAlpha
  */
 public function testAlpha()
 {
     $color = new ILess_Color();
     $this->assertEquals(1, $color->getAlpha());
 }