コード例 #1
0
ファイル: FunctionRegistry.php プロジェクト: poef/ariadne
 /**
  * Return a mix of $color1 and $color2 with given $weightPercentage (defaults to 50%)
  *
  * @param ILess_Node $color1
  * @param ILess_Node $color2
  * @param ILess_Node_Dimension $weightPercentage
  * @return ILess_Node_Color
  * @link http://sass-lang.com
  * @copyright 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
  */
 public function mix(ILess_Node $color1, ILess_Node $color2, ILess_Node_Dimension $weightPercentage = null)
 {
     if (!$color1 instanceof ILess_Node_Color) {
         return $color1;
     } elseif (!$color2 instanceof ILess_Node_Color) {
         return $color1;
     }
     if (!$weightPercentage) {
         $weightPercentage = new ILess_Node_Dimension('50', '%');
     }
     $p = $weightPercentage->value / 100.0;
     $w = $p * 2 - 1;
     $a = $color1->getAlpha(true) - $color2->getAlpha(true);
     $w1 = (($w * $a == -1 ? $w : ($w + $a) / (1 + $w * $a)) + 1) / 2;
     $w2 = 1 - $w1;
     $color1Rgb = $color1->getRGB();
     $color2Rgb = $color2->getRGB();
     $rgb = array($color1Rgb[0] * $w1 + $color2Rgb[0] * $w2, $color1Rgb[1] * $w1 + $color2Rgb[1] * $w2, $color1Rgb[2] * $w1 + $color2Rgb[2] * $w2);
     $alpha = $color1->getAlpha(true) * $p + $color2->getAlpha(true) * (1 - $p);
     return new ILess_Node_Color($rgb, $alpha);
 }