Difference between revisions of "GradientValue"

From Second Life Wiki
Jump to navigation Jump to search
m (fixed check)
m (<lsl> tag to <source>)
 
(3 intermediate revisions by one other user not shown)
Line 5: Line 5:
|p2_type=vector|p2_name=end|p2_desc=Gradient end color
|p2_type=vector|p2_name=end|p2_desc=Gradient end color
|p3_type=float|p3_name=percentage|p3_desc=Percentage in the range (0.0 to 100.0) from start to end
|p3_type=float|p3_name=percentage|p3_desc=Percentage in the range (0.0 to 100.0) from start to end
|return_type=vector|return_text=that is the color vector between {{LSLP|start}} and {{LSLP|end}} depending upon {{LSLP|percentage}} if percentage is in range, else returns <code>{{LSL VR|-1|-1|-1}}</code>.
|return_type=vector|return_text=that is the color vector between {{LSLP|start}} and {{LSLP|end}} depending upon {{LSLP|percentage}} if the vector between can be calculated, else returns <code>{{LSL VR|-1|-1|-1}}</code>.
|func_footnote
|func_footnote
|caveats
|caveats
|spec=
|spec=
<lsl>
<source lang="lsl2">
//  Created by Ugleh Ulrik
//  Created by Ugleh Ulrik


vector GradientValue(vector start, vector end, float percentage)
vector GradientValue(vector start, vector end, float percentage)
{
{
     if (percentage < 0.0 || 100.0 < percentage) return <-1, -1, -1>;
    list colorParams = [start.x, start.y, start.z, end.x, end.y, end.z];
 
     if (percentage < 0.0
        || 100.0 < percentage
        || llListStatistics(LIST_STAT_MIN, colorParams) < 0.0
        || 1.0 < llListStatistics(LIST_STAT_MAX, colorParams))
    {
        return <-1, -1, -1>;
    }
 
     percentage /= 100.0;// convert to decimal for further use
     percentage /= 100.0;// convert to decimal for further use


     float red  = start.x + percentage*(end.x - start.x);
     return start + percentage*(end - start);
    float green = start.y + percentage*(end.y - start.y);
    float blue  = start.z + percentage*(end.z - start.z);
 
    return <red, green, blue>;
}
}
</lsl>
</source>
|examples=
|examples=
<lsl>
<source lang="lsl2">
vector GradientValue(vector start, vector end, float percentage)
vector GradientValue(vector start, vector end, float percentage)
{
{
     if (percentage < 0.0 || 100.0 < percentage) <-1, -1, -1>;
    list colorParams = [start.x, start.y, start.z, end.x, end.y, end.z];
 
     if (percentage < 0.0
        || 100.0 < percentage
        || llListStatistics(LIST_STAT_MIN, colorParams) < 0.0
        || 1.0 < llListStatistics(LIST_STAT_MAX, colorParams))
    {
        return <-1, -1, -1>;
    }
 
     percentage /= 100.0;
     percentage /= 100.0;


     float red  = start.x + percentage*(end.x - start.x);
     return start + percentage*(end - start);
    float green = start.y + percentage*(end.y - start.y);
    float blue  = start.z + percentage*(end.z - start.z);
 
    return <red, green, blue>;
}
}


Line 52: Line 62:
     }
     }
}
}
</lsl>
</source>
|helpers
|helpers
|notes
|notes

Latest revision as of 14:15, 22 January 2015

Summary

Function: vector GradientValue( vector start, vector end, float percentage );

Returns a vector that is the color vector between start and end depending upon percentage if the vector between can be calculated, else returns <-1, -1, -1>.

• vector start Gradient start color
• vector end Gradient end color
• float percentage Percentage in the range (0.0 to 100.0) from start to end

Specification

//  Created by Ugleh Ulrik

vector GradientValue(vector start, vector end, float percentage)
{
    list colorParams = [start.x, start.y, start.z, end.x, end.y, end.z];

    if (percentage < 0.0
        || 100.0 < percentage
        || llListStatistics(LIST_STAT_MIN, colorParams) < 0.0
        || 1.0 < llListStatistics(LIST_STAT_MAX, colorParams))
    {
        return <-1, -1, -1>;
    }

    percentage /= 100.0;// convert to decimal for further use

    return start + percentage*(end - start);
}

Examples

vector GradientValue(vector start, vector end, float percentage)
{
    list colorParams = [start.x, start.y, start.z, end.x, end.y, end.z];

    if (percentage < 0.0
        || 100.0 < percentage
        || llListStatistics(LIST_STAT_MIN, colorParams) < 0.0
        || 1.0 < llListStatistics(LIST_STAT_MAX, colorParams))
    {
        return <-1, -1, -1>;
    }

    percentage /= 100.0;

    return start + percentage*(end - start);
}

default
{
    state_entry()
    {
        vector maroon = <0.522, 0.078, 0.294>;
        vector teal   = <0.224, 0.800, 0.800>;

        vector ColorBetween = GradientValue(maroon, teal, 50.0);
//             ColorBetween = <0.373, 0.439, 0.547>

        if (ColorBetween != <-1, -1, -1>)
            llSetColor(ColorBetween, ALL_SIDES);
    }
}

See Also

Constants

•  PRIM_COLOR
•  CHANGED_COLOR

Functions

•  llGetColor
•  llGetLinkPrimitiveParams
•  llSetColor
•  llSetLinkColor

Articles

•  Color and Scripting
•  Color