|
|
If the macro is written like below, then
it can also handle negative angles for
the Hue component.
Tor Olav
#macro ConvertHSLtoRGB(vColor)
// Extract Hue, Saturation and Lightness components
#local H = vColor.x;
#local S = vColor.y;
#local L = vColor.z;
#local Angle = mod(H, 360) + (H < 0 ? 360 : 0);
// Construct RGB from Hue
#switch (Angle)
#range (0, 120)
#local R = (120 - H)/60;
#local G = ( H - 0)/60;
#local B = 0;
#break
#range (120, 240)
#local R = 0;
#local G = (240 - H)/60;
#local B = ( H - 120)/60;
#break
#range (240, 360)
#local R = ( H - 240)/60;
#local G = 0;
#local B = (360 - H)/60;
#break
#end // switch
#local vClampedRGB = <min(R, 1), min(G, 1), min(B, 1)>;
// Incorporate saturation and lightness
(((1 - S)*<1, 1, 1> + S*vClampedRGB)*L)
#end // macro ConvertHSLtoRGB
Tor Olav Kristensen wrote:
>...
> But if I were to write this macro from
> scratch, then i would have used an angle
> (in degrees) for the Hue component.
>...
> Then the macro would have looked like this:
>
> #macro ConvertHSLtoRGB(vColor)
>
> // Extract Hue, Saturation and Lightness components
> #local H = vColor.x;
> #local S = vColor.y;
> #local L = vColor.z;
>
> // Construct RGB from Hue
> #switch (mod(H, 360))
> #range (0, 120)
> #local R = (120 - H)/60;
> #local G = ( H - 0)/60;
> #local B = 0;
> #break
> #range (120, 240)
> #local R = 0;
> #local G = (240 - H)/60;
> #local B = ( H - 120)/60;
> #break
> #range (240, 360)
> #local R = ( H - 240)/60;
> #local G = 0;
> #local B = (360 - H)/60;
> #break
> #end // switch
>
> #local vClampedRGB = <min(R, 1), min(G, 1), min(B, 1)>;
>
> // Incorporate saturation and lightness
> (((1 - S)*<1, 1, 1> + S*vClampedRGB)*L)
>
> #end // macro ConvertHSLtoRGB
Post a reply to this message
|
|