Progress Bar
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
This is a script to create very useful and realistic looking progress or health bars. They are suitable for creating quick, direct and visual feedback to a user without resorting to exotic dedicated prim displays.
License
<lsl> //===================================================// // Progress Bar v1 // // "September 24 2009", "04:24:00 GMT-0" // // Copyright (C) 2009, Nexii Malthus (cc-by) // // http://creativecommons.org/licenses/by/3.0/ // //===================================================// </lsl>
Function of Interest
Character Sets <lsl> list Charset_Shade = [" ","░","▒","▓","█"];// Too rough list Charset_LeftRight = [" ","▏","▎","▍","▌","▋","▊","▉","█"];// Works Best list Charset_UpDown = [" ","▁","▂","▃","▄","▅","▆","▇","█"];// Good as single-bar progress bar list Charset_Central = [" ","❘","❙","❚","█"];// Too steppy list Charset_Box = ["□","▧","▨","▩","■"]; list Charset_Circle = ["○","◔","◑","◕","●"]; list Charset_Boxes = [" ","▝","▐","▟","█"]; list Charset_Dice = ["⚀","⚁","⚂","⚃","⚄","⚅"];// Hard to perceive detail list Charset_Braille = ["⠀","⠁","⠃","⠇","⠏","⠟","⠿"]; </lsl> Progress Bars Function <lsl> string Bars( float Cur, integer Bars, list Charset ){
// Input = 0.0 to 1.0
// Bars = char length of progress bar
// Charset = [Blank,<Shades>,Solid];
integer Shades = llGetListLength(Charset)-1;
Cur *= Bars;
integer Solids = llFloor( Cur );
integer Shade = llRound( (Cur-Solids)*Shades );
integer Blanks = Bars - Solids - 1;
string str;
while( Solids-- >0 ) str += llList2String( Charset, -1 );
if( Blanks >= 0 ) str += llList2String( Charset, Shade );
while( Blanks-- >0 ) str += llList2String( Charset, 0 );
return str; }
</lsl>
Full Test Script
<lsl> string cleanF( float F ){// Clean a float for debug output
string S = (string)F;
while( llGetSubString( S, -1, -1 ) == "0" )// Clear zeroes
S = llGetSubString( S, 0, -2 );
if( llGetSubString( S, -1, -1 ) == "." )// Cut dot if lone
S = llGetSubString( S, 0, -2 );
return S; }
float fCub_I( float t, float b, float c, float d ){
return c * llPow( t/d, 3 ) + b;}
float fCirc_I( float t, float b, float c, float d ){
return c * ( 1 - llSqrt( 1 - ( t /= d ) * t ) ) + b;}
float fExpo_IO( float t, float b, float c, float d ){
if( ( t /= d / 2 ) < 1 )
return c / 2 * llPow( 2, 10 * ( t - 1 ) ) + b;
return c / 2 * ( -llPow( 2 , -10 * --t ) + 2 ) + b;}
list Charset_Shade = [" ","░","▒","▓","█"];
list Charset_LeftRight = [" ","▏","▎","▍","▌","▋","▊","▉","█"];
list Charset_UpDown = [" ","▁","▂","▃","▄","▅","▆","▇","█"];
list Charset_Central = [" ","❘","❙","❚","█"];
list Charset_Box = ["□","▧","▨","▩","■"];
list Charset_Circle = ["○","◔","◑","◕","●"];
list Charset_Boxes = [" ","▝","▐","▟","█"];
list Charset_Dice = ["⚀","⚁","⚂","⚃","⚄","⚅"];
list Charset_Braille = ["⠀","⠁","⠃","⠇","⠏","⠟","⠿"];
string Bars( float Cur, integer Bars, list Charset ){
// Input = 0.0 to 1.0
// Bars = char length of progress bar
// Charset = [Blank,<Shades>,Solid];
integer Shades = llGetListLength(Charset)-1;
Cur *= Bars;
integer Solids = llFloor( Cur );
integer Shade = llRound( (Cur-Solids)*Shades );
integer Blanks = Bars - Solids - 1;
string str;
while( Solids-- >0 ) str += llList2String( Charset, -1 );
if( Blanks >= 0 ) str += llList2String( Charset, Shade );
while( Blanks-- >0 ) str += llList2String( Charset, 0 );
return str; }
float Energy = 40.0; float EnergyCap = 100.0;
float Dir = 1;
default {
state_entry(){
llSetText("", <.0,.5,1.>, 1 );
llSetTimerEvent( 0.1 );
}
timer(){
Energy += 2 * Dir;
if( Energy > EnergyCap ){
Energy = EnergyCap; Dir = -Dir;
} else if( Energy < 0 ){
Energy = 0; Dir = -Dir;
}
float t = Energy / EnergyCap;
float Bar1 = t;
float Bar2 = fCirc_I(t,0,1,1);
float Bar3 = fExpo_IO(1-t,0,1,1);
float Bar4 = t;
string Text;
if( Dir == TRUE ) Text += "⟾ ";
else Text += "⟸ ";
Text += Bars( Bar1, 10, Charset_LeftRight )+"\n";
Text += Bars( Bar2, 8, Charset_UpDown )+"\n";
Text += Bars( Bar2, 8, Charset_Braille )+"\n";
Text += Bars( Bar3, 8, Charset_Shade )+"\n⟦ ";
if( Dir == TRUE ) Text += "► ";
else Text += "◄ ";
Text += Bars( Bar4, 1, Charset_LeftRight )+" | ";
if( Dir == TRUE ) Text += "▲ ";
else Text += "▼ ";
Text += Bars( Bar4, 1, Charset_UpDown )+" | ";
Text += Bars( Bar4, 1, Charset_Central )+" ⟧\n⟦ ";
Text += Bars( Bar4, 1, Charset_Box )+" | ";
if( Dir == TRUE ) Text += "⟳ ";
else Text += "⟲ ";
Text += Bars( Bar4, 1, Charset_Circle )+" ";
Text += Bars( Bar4, 1, Charset_Boxes )+" ⟧\n";
Text += "\n"+cleanF(Energy)+" / "+cleanF(EnergyCap);
vector Color = llVecNorm(<1-t,t,0>);
llSetText(Text,Color,1);
}
} </lsl>