Difference between revisions of "GradientValue"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL_Function |func=GradientValue |mode=user |p1_type=vector|p1_name=beginColor|p1_desc=The Starting Vector Color |p2_type=vector|p2_name=endColor|p2_desc=The Ending Vector Colo…")
 
Line 11: Line 11:
//Created by Ugleh Ulrik
//Created by Ugleh Ulrik
vector GradientValue(vector beginColor,vector endColor, float percentage){
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 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));
Line 17: Line 20:
}
}
</lsl>
</lsl>
Note in the return we use /255 to convert a RGB value to an SL Safe Vector. If you are originally using an SL Vector then remove /255.
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){
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 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));

Revision as of 19:38, 29 October 2011

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()
   {

vector Red = <255,0,0>; vector Blue = <0,0,255>; //The Above Vectors are not SL safe, to use SL Safe Vectors you would do //vector Red = <1,0,0>; //vector Blue = <0,0,1>; vector ColorBetween = GradientValue(Red,Blue,0.50); //I use 0.50 which is half, so I am getting the color between Red and Blue, which is Purple. llSetColor(ColorBetween,ALL_SIDES);

   }

}

</lsl>