/** * @param Less_Tree_Color $color1 */ public function mix($color1 = null, $color2 = null, $weight = null) { if (!$color1 instanceof Less_Tree_Color) { throw new Less_Exception_Compiler('The first argument to mix must be a color' . ($color1 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '')); } if (!$color2 instanceof Less_Tree_Color) { throw new Less_Exception_Compiler('The second argument to mix must be a color' . ($color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '')); } if (!$weight) { $weight = new Less_Tree_Dimension('50', '%'); } if (!$weight instanceof Less_Tree_Dimension) { throw new Less_Exception_Compiler('The third argument to contrast must be a percentage' . ($weight instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '')); } $p = $weight->value / 100.0; $w = $p * 2 - 1; $hsl1 = $color1->toHSL(); $hsl2 = $color2->toHSL(); $a = $hsl1['a'] - $hsl2['a']; $w1 = (($w * $a == -1 ? $w : ($w + $a) / (1 + $w * $a)) + 1) / 2; $w2 = 1 - $w1; $rgb = array($color1->rgb[0] * $w1 + $color2->rgb[0] * $w2, $color1->rgb[1] * $w1 + $color2->rgb[1] * $w2, $color1->rgb[2] * $w1 + $color2->rgb[2] * $w2); $alpha = $color1->alpha * $p + $color2->alpha * (1 - $p); return new Less_Tree_Color($rgb, $alpha); }
/** * @param Less_Tree_Color $color1 */ public function mix($color1, $color2, $weight = null){ if (!$weight) { $weight = new Less_Tree_Dimension('50', '%'); } $p = $weight->value / 100.0; $w = $p * 2 - 1; $hsl1 = $color1->toHSL(); $hsl2 = $color2->toHSL(); $a = $hsl1['a'] - $hsl2['a']; $w1 = (((($w * $a) == -1) ? $w : ($w + $a) / (1 + $w * $a)) + 1) / 2; $w2 = 1 - $w1; $rgb = array($color1->rgb[0] * $w1 + $color2->rgb[0] * $w2, $color1->rgb[1] * $w1 + $color2->rgb[1] * $w2, $color1->rgb[2] * $w1 + $color2->rgb[2] * $w2); $alpha = $color1->alpha * $p + $color2->alpha * (1 - $p); return new Less_Tree_Color($rgb, $alpha); }