$h=fmod(self::_number($h),360)/360;// Classic % operator will change float to int
$s=self::_clamp(self::_number($s));
$l=self::_clamp(self::_number($l));
$a=self::_clamp(self::_number($a));
$m2=$l<=0.5?$l*($s+1):$l+$s-$l*$s;
$m1=$l*2-$m2;
return$this->rgba(
self::hsla_hue($h+1/3,$m1,$m2)*255,
self::hsla_hue($h,$m1,$m2)*255,
self::hsla_hue($h-1/3,$m1,$m2)*255,
$a
);
}
/**
* @param float $h
* @param float $m1
* @param float $m2
*/
publicfunctionhsla_hue($h,$m1,$m2){
$h=$h<0?$h+1:($h>1?$h-1:$h);
if($h*6<1){
return$m1+($m2-$m1)*$h*6;
}elseif($h*2<1){
return$m2;
}elseif($h*3<2){
return$m1+($m2-$m1)*(2/3-$h)*6;
}else{
return$m1;
}
}
publicfunctionhsv($h,$s,$v){
return$this->hsva($h,$s,$v,1.0);
}
/**
* @param Less_Tree|float $h
* @param Less_Tree|float $s
* @param Less_Tree|float $v
* @param float $a
*/
publicfunctionhsva($h,$s,$v,$a){
$h=((self::_number($h)%360)/360)*360;
$s=self::_number($s);
$v=self::_number($v);
$a=self::_number($a);
$i=(int)floor((int)($h/60)%6);
$f=($h/60)-$i;
$vs=[
$v,
$v*(1-$s),
$v*(1-$f*$s),
$v*(1-(1-$f)*$s)
];
$perm=[
[0,3,1],
[2,0,1],
[1,0,3],
[1,2,0],
[3,1,0],
[0,1,2]
];
return$this->rgba(
$vs[$perm[$i][0]]*255,
$vs[$perm[$i][1]]*255,
$vs[$perm[$i][2]]*255,
$a
);
}
publicfunctionhue($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to hue must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$c=$color->toHSL();
returnnewLess_Tree_Dimension($c['h']);
}
publicfunctionsaturation($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to saturation must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$c=$color->toHSL();
returnnewLess_Tree_Dimension($c['s']*100,'%');
}
publicfunctionlightness($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to lightness must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$c=$color->toHSL();
returnnewLess_Tree_Dimension($c['l']*100,'%');
}
publicfunctionhsvhue($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to hsvhue must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$hsv=$color->toHSV();
returnnewLess_Tree_Dimension($hsv['h']);
}
publicfunctionhsvsaturation($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to hsvsaturation must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$hsv=$color->toHSV();
returnnewLess_Tree_Dimension($hsv['s']*100,'%');
}
publicfunctionhsvvalue($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to hsvvalue must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$hsv=$color->toHSV();
returnnewLess_Tree_Dimension($hsv['v']*100,'%');
}
publicfunctionred($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to red must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
returnnewLess_Tree_Dimension($color->rgb[0]);
}
publicfunctiongreen($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to green must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
returnnewLess_Tree_Dimension($color->rgb[1]);
}
publicfunctionblue($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to blue must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
returnnewLess_Tree_Dimension($color->rgb[2]);
}
publicfunctionalpha($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to alpha must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
$c=$color->toHSL();
returnnewLess_Tree_Dimension($c['a']);
}
publicfunctionluma($color=null){
if(!$colorinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The first argument to luma must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to luminance must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to saturate must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to saturate must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to desaturate must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to desaturate must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to lighten must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to lighten must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to darken must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to darken must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to fadein must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to fadein must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to fadeout must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to fadeout must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to fade must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to fade must be a percentage'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to spin must be a color'.($colorinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$amountinstanceofLess_Tree_Dimension){
thrownewLess_Exception_Compiler('The second argument to spin must be a number'.($amountinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler("The first argument must be a color, $type given".($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler("The second argument must be a color, $type given".($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler("The third argument must be a percentage, $type given".($weightinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The second argument to contrast must be a color'.($darkinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$lightinstanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The third argument to contrast must be a color'.($lightinstanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to unit must be a number'.($valinstanceofLess_Tree_Operation?'. Have you forgotten parenthesis?':'.'));
thrownewLess_Exception_Compiler('The first argument to multiply must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to multiply must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to screen must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to screen must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to overlay must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to overlay must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to softlight must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to softlight must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to hardlight must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to hardlight must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to difference must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to difference must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to exclusion must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to exclusion must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to average must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to average must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
thrownewLess_Exception_Compiler('The first argument to negation must be a color'.($color1instanceofLess_Tree_Expression?' (did you forgot commas?)':''));
}
if(!$color2instanceofLess_Tree_Color){
thrownewLess_Exception_Compiler('The second argument to negation must be a color'.($color2instanceofLess_Tree_Expression?' (did you forgot commas?)':''));