User:Adicted Waco/Projects/HSL2RGB

From Second Life Wiki
Jump to: navigation, search
Subpage Table Of Contents

Adicted Waco

HSL2RGB

A Script That Converts A Hue To A RGB (Needs Work) <lsl> float hue_2_rgb(float temp1,float temp2,float temp3) {

       if (temp3 < 0)
       {
               temp3 += 1;
       }
       if (temp3 > 1)
       {
               temp3 -= 1;
       }
       if (6.0*temp3 < 1)
       {
           return (temp1+(temp2-temp1)*6.0*temp3);
       }
       else if (2.0*temp3 < 1)
       {
           return (temp2);
       }
       else if (3.0*temp3 < 2)
       {
           return (temp1+(temp2-temp1)*((2.0/3.0)-temp3)*6.0);
       }
       else
       {
           return (temp1);
       }

} vector HSL2RGB(float h, float s, float l) {

   float var_1;
   float var_2;
   if (s == 0)
   {
           return <l, l, l>;
   }
   else
   {
       if (l < 0.5)
       {
               var_2 = l * (1 + s);
       }
       else
       {
               var_2 = (l + s) - (s * l);
       }
       var_1 = 2 * l - var_2;
       return <
       hue_2_rgb(var_1,var_2,h + (1.0 / 3.0)),
       hue_2_rgb(var_1,var_2,h), 
       hue_2_rgb(var_1,var_2,h - (1.0 / 3.0))>;
       }

} default {

   state_entry()
   {//Example Vales Are For Green = <0,1,0> 
       float h = 120.0/360.0;
       float s = 100.0/100.0;
       float l = 50.0/100.0;
       llOwnerSay((string)HSL2RGB(h, s, l));
   }

}

</lsl>