Difference between revisions of "GradientValue"

From Second Life Wiki
Jump to navigation Jump to search
(some general readability improvements and some for non-widescreens when viewing the page specifically)
Line 10: Line 10:
<lsl>
<lsl>
//Created by Ugleh Ulrik
//Created by Ugleh Ulrik
vector GradientValue(vector beginColor,vector endColor, float percentage){
 
//If vectors are in SL format (1.0 max) then do a multiplication of 255.
vector GradientValue(vector beginColor, vector endColor, float percentage)
//beginColor = beginColor * 255;
{
//endColor = endColor * 255;
    // If vectors are in SL format (1.0 max) then do a multiplication of 255.
    // beginColor = beginColor * 255;
    // endColor = endColor * 255;
 
     float red = beginColor.x + (integer)(percentage * (endColor.x - beginColor.x));
     float red = beginColor.x + (integer)(percentage * (endColor.x - beginColor.x));
     float green = beginColor.y + (integer)(percentage * (endColor.y - beginColor.y));
     float green = beginColor.y + (integer)(percentage * (endColor.y - beginColor.y));
     float blue = beginColor.z + (integer)(percentage * (endColor.z - beginColor.z));
     float blue = beginColor.z + (integer)(percentage * (endColor.z - beginColor.z));
     return <red,green,blue>/255;
     return <red,green,blue>/255;
}
}
</lsl>
</lsl>
Note in the return we use /255 to convert a RGB value to an SL Safe Vector. The math assumes it is a normal RGB value during the math, so if it isnt you need to uncomment the multiplication lines.
Note in the return we use /255 to convert a RGB value to an SL Safe Vector. The math assumes it is a normal RGB value during the math, so if it isnt you need to uncomment the multiplication lines.
|examples=<lsl>
|examples=
<lsl>
//Created by Ugleh Ulrik
//Created by Ugleh Ulrik
vector GradientValue(vector beginColor,vector endColor, float percentage){
 
//If vectors are in SL format (1.0 max) then do a multiplication of 255.
vector GradientValue (vector beginColor, vector endColor, float percentage)
//beginColor = beginColor * 255;
{
//endColor = endColor * 255;
    // If vectors are in SL format (1.0 max) then do a multiplication of 255.
    // beginColor = beginColor * 255;
    // endColor = endColor * 255;
 
     float red = beginColor.x + (integer)(percentage * (endColor.x - beginColor.x));
     float red = beginColor.x + (integer)(percentage * (endColor.x - beginColor.x));
     float green = beginColor.y + (integer)(percentage * (endColor.y - beginColor.y));
     float green = beginColor.y + (integer)(percentage * (endColor.y - beginColor.y));
     float blue = beginColor.z + (integer)(percentage * (endColor.z - beginColor.z));
     float blue = beginColor.z + (integer)(percentage * (endColor.z - beginColor.z));
     return <red,green,blue>/255;
 
     return <red, green, blue>/255;
}  
}  


Line 37: Line 46:
     state_entry()
     state_entry()
     {
     {
vector Red = <255,0,0>;
        // The following vectors are not SL safe, to use SL Safe Vectors you would do
vector Blue = <0,0,255>;
        // vector Red = <1.0, 0.0, 0.0>;
//The Above Vectors are not SL safe, to use SL Safe Vectors you would do
        // vector Blue = <0.0, 0.0, 1.0>;
//vector Red = <1,0,0>;
 
//vector Blue = <0,0,1>;
        vector Red = <255.0, 0.0, 0.0>;
vector ColorBetween = GradientValue(Red,Blue,0.50);
        vector Blue = <0.0, 0.0, 255.0>;
//I use 0.50 which is half, so I am getting the color between Red and Blue, which is Purple.
 
llSetColor(ColorBetween,ALL_SIDES);
        // I use 0.50 which is half, so I am getting the color between Red and Blue, which is Purple.
        vector ColorBetween = GradientValue(Red, Blue, 0.50);
 
        llSetColor(ColorBetween, ALL_SIDES);
     }
     }
}
}
</lsl>
</lsl>
|helpers
|helpers

Revision as of 11:19, 30 September 2012

Summary

Function: GradientValue( vector beginColor, vector endColor, float percentage );

Returns a vector between beginColor and endColor depending on the percentage param.

• vector beginColor The Starting Vector Color
• vector endColor The Ending Vector Color
• float percentage The Percentage from beginColor to endColor.

Percentage goes from 0.0 to 1.0 where 0.5 is 50%.

Specification

<lsl> //Created by Ugleh Ulrik

vector GradientValue(vector beginColor, vector endColor, float percentage) {

   // If vectors are in SL format (1.0 max) then do a multiplication of 255.
   // beginColor = beginColor * 255;
   // endColor = endColor * 255;
   float red = beginColor.x + (integer)(percentage * (endColor.x - beginColor.x));
   float green = beginColor.y + (integer)(percentage * (endColor.y - beginColor.y));
   float blue = beginColor.z + (integer)(percentage * (endColor.z - beginColor.z));
   return <red,green,blue>/255;

} </lsl> Note in the return we use /255 to convert a RGB value to an SL Safe Vector. The math assumes it is a normal RGB value during the math, so if it isnt you need to uncomment the multiplication lines.

Examples

<lsl> //Created by Ugleh Ulrik

vector GradientValue (vector beginColor, vector endColor, float percentage) {

   // If vectors are in SL format (1.0 max) then do a multiplication of 255.
   // beginColor = beginColor * 255;
   // endColor = endColor * 255;
   float red = beginColor.x + (integer)(percentage * (endColor.x - beginColor.x));
   float green = beginColor.y + (integer)(percentage * (endColor.y - beginColor.y));
   float blue = beginColor.z + (integer)(percentage * (endColor.z - beginColor.z));
   return <red, green, blue>/255;

}

default {

   state_entry()
   {
       // The following vectors are not SL safe, to use SL Safe Vectors you would do
       // vector Red = <1.0, 0.0, 0.0>;
       // vector Blue = <0.0, 0.0, 1.0>;
       vector Red = <255.0, 0.0, 0.0>;
       vector Blue = <0.0, 0.0, 255.0>;
       // I use 0.50 which is half, so I am getting the color between Red and Blue, which is Purple.
       vector ColorBetween = GradientValue(Red, Blue, 0.50);
       llSetColor(ColorBetween, ALL_SIDES);
   }

}

</lsl>