POV-Ray : Newsgroups : povray.beta-test : Colors.inc-macros incomplete : Re: Colors.inc-macros incomplete Server Time
5 Nov 2024 03:18:10 EST (-0500)
  Re: Colors.inc-macros incomplete  
From: Tor Olav Kristensen
Date: 10 Sep 2001 22:01:27
Message: <3B9D7039.80799D1A@hotmail.com>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.