Difference between revisions of "Progress Bar"
(Fancy new script of awesome) |
|||
Line 12: | Line 12: | ||
//===================================================// | //===================================================// | ||
</lsl> | </lsl> | ||
== Function of | |||
== Function == | |||
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> | |||
Some possible character sets | |||
<lsl> | <lsl> | ||
// Bars | |||
list Charset_Shade = [" ","░","▒","▓","█"];// Too rough | list Charset_Shade = [" ","░","▒","▓","█"];// Too rough | ||
list Charset_LeftRight = [" ","▏","▎","▍","▌","▋","▊","▉","█"];// Works Best | list Charset_LeftRight = [" ","▏","▎","▍","▌","▋","▊","▉","█"];// Works Best | ||
list Charset_UpDown = [" ","▁","▂","▃","▄","▅","▆","▇","█"];// Good as single-bar progress bar | list Charset_UpDown = [" ","▁","▂","▃","▄","▅","▆","▇","█"];// Good as single-bar progress bar | ||
list Charset_Central = [" ","❘","❙","❚","█"];// Too steppy | list Charset_Central = [" ","❘","❙","❚","█"];// Too steppy | ||
list Charset_Braille = ["⠀","⠁","⠃","⠇","⠏","⠟","⠿"]; | |||
// Random Single-char | |||
list Charset_Box = ["□","▧","▨","▩","■"]; | list Charset_Box = ["□","▧","▨","▩","■"]; | ||
list Charset_Circle = ["○","◔","◑","◕","●"]; | list Charset_Circle = ["○","◔","◑","◕","●"]; | ||
list Charset_Boxes = [" ","▝","▐","▟","█"]; | list Charset_Boxes = [" ","▝","▐","▟","█"]; | ||
list Charset_Dice = ["⚀","⚁","⚂","⚃","⚄","⚅"];// Hard to perceive detail | list Charset_Dice = ["⚀","⚁","⚂","⚃","⚄","⚅"];// Hard to perceive detail | ||
list | |||
// Directional | |||
list Charset_Arrow1 = ["↑","↗","→","↘","↓","↙","←","↖"]; | |||
list Charset_Arrow2 = ["⇑","⇗","⇒","⇘","⇓","⇙","⇐","⇖"]; | |||
list Charset_Arrow3 = ["⬆","⬈","➨","⬊","⬇","⬋","⬅","⬉"]; | |||
</lsl> | </lsl> | ||
== Simple Test == | |||
<lsl> | <lsl> | ||
list Charset_LeftRight = [" ","▏","▎","▍","▌","▋","▊","▉","█"]; | |||
string Bars( float Cur, integer Bars, list Charset ){ | string Bars( float Cur, integer Bars, list Charset ){ | ||
// Input = 0.0 to 1.0 | // Input = 0.0 to 1.0 | ||
Line 41: | Line 73: | ||
while( Blanks-- >0 ) str += llList2String( Charset, 0 ); | while( Blanks-- >0 ) str += llList2String( Charset, 0 ); | ||
return str; } | return str; } | ||
default { | |||
touch_start( integer d ){ | |||
float Input; | |||
integer Length = 10; | |||
for( Input = 0.0; Input < 1.0; Input += 0.02 ){ | |||
string Text = "▕"+Bars( Input, Length, Charset_LeftRight )+"▏"; | |||
llSetText( Text, <0,0,0>, 1.0 ); | |||
llSleep( 0.1 ); | |||
} | |||
} | |||
} | |||
</lsl> | </lsl> | ||
== Full Test Script == | == Full Test Script == |
Revision as of 21:09, 23 September 2009
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
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>
Some possible character sets <lsl> // Bars 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_Braille = ["⠀","⠁","⠃","⠇","⠏","⠟","⠿"];
// Random Single-char list Charset_Box = ["□","▧","▨","▩","■"]; list Charset_Circle = ["○","◔","◑","◕","●"]; list Charset_Boxes = [" ","▝","▐","▟","█"]; list Charset_Dice = ["⚀","⚁","⚂","⚃","⚄","⚅"];// Hard to perceive detail
// Directional list Charset_Arrow1 = ["↑","↗","→","↘","↓","↙","←","↖"]; list Charset_Arrow2 = ["⇑","⇗","⇒","⇘","⇓","⇙","⇐","⇖"]; list Charset_Arrow3 = ["⬆","⬈","➨","⬊","⬇","⬋","⬅","⬉"]; </lsl>
Simple Test
<lsl> list Charset_LeftRight = [" ","▏","▎","▍","▌","▋","▊","▉","█"];
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; }
default {
touch_start( integer d ){ float Input; integer Length = 10; for( Input = 0.0; Input < 1.0; Input += 0.02 ){ string Text = "▕"+Bars( Input, Length, Charset_LeftRight )+"▏"; llSetText( Text, <0,0,0>, 1.0 ); llSleep( 0.1 ); } }
} </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>