gradientValue
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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>