gradientValue

From Second Life Wiki
Revision as of 19:15, 11 October 2011 by Ugleh Ulrik (talk | contribs) (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…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

   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. If you are originally using an SL Vector then remove /255.

Examples

<lsl> //Created by Ugleh Ulrik vector GradientValue(vector beginColor,vector endColor, float percentage){

   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>