User:Void Singer/Programs

From Second Life Wiki
< User:Void Singer
Revision as of 23:28, 15 May 2009 by Void Singer (talk | contribs) (New free use script, yay)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Color Selector

Features:

  • Dialog driven.
  • Save and Recall.
  • Full 16 million+ colors.
  • Colors multiple linked prims at once.
  • Compatible with standard color picker displays.

Script

<lsl> /// v7-D Adv Color Picker v1.2 license Text - DO NOT REMOVE! /// // // // This script is provided freely by Void Singer // // https://wiki.secondlife.com/wiki/User:Void_Singer // // under the Creative Commons CC-BY license found at // // http://creativecommons.org/licenses/by/3.0/ // // A plain text readable copy of this notice must be // // made available with all usages. // // // ////////////////////////////////////////////////////////////////

//-- That means you can use, copy, modify, give away, or //-- even sell the code; so long as you attribute it with //-- the above license text that may be read by the user.

//--// ~ IMPORTANT NOTE ~ //--//

// // // This Script MUST be // // placed in one of the // // prims it is going to // // modify or it will not // // work properly! // // // // All Prims that are to // // to modified at the // // same time MUST have // // the SAME NAME !!! // // // ////////////////////////////////

key gKeyOwner; integer gIdxPanel; integer gChnDialog; list gLstTargets; integer gIntTargets; vector gColDefault = <0.0, 0.0, 0.0>; string gStrProduct = "v7-D Adv Color Picker v1.2"; list gLstButtons = ["-1", "-8", "-64", "+1", "+8", "+64",

                      "Recall", "Done!", "Save",
                      "All Colors", "Red Only", "Green Only", "Blue Only"];

list gLstBValues = [-0.003922, -0.031373, -0.250980, 0.003922, 0.031373, 0.250980,

                      <1.0, 1.0, 1.0>, <1.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 1.0>];


fColorDialog(){

 vector vColTemp = llGetColor( ALL_SIDES ) * 255;
  //-- build the dialog to send
 llDialog( gKeyOwner,
           gStrProduct + "\n\nModifying "
           + llList2String( gLstButtons, gIdxPanel )
           + "\n\nCurrent Values (0-255):\n"
           + "R:" + (string)llRound( vColTemp.x )
           + ", G:" + (string)llRound( vColTemp.y )
           + ", B:" + (string)llRound( vColTemp.z )
           + " = #" + fFloat2HexStr( vColTemp.x )
           + fFloat2HexStr( vColTemp.y )
           + fFloat2HexStr( vColTemp.x ),
           llDeleteSubList( gLstButtons, gIdxPanel, gIdxPanel ),
           gChnDialog );
 llSetTimerEvent( 45.0 );

}

string fFloat2HexStr( float vFltInput ){

 integer vBitInput = llRound( vFltInput );
 string  vStrValue = "0123456789ABCDEF";
 return llGetSubString( vStrValue, gIntTargets = vBitInput / 16, gIntTargets )
        + llGetSubString( vStrValue, gIntTargets = vBitInput % 16, gIntTargets );

}

fSetColor( vector vColUse ){

  //-- loop through target list of linked prims
 gIntTargets = gLstTargets != [];
 @Loop;
   llSetLinkColor( llList2Integer( gLstTargets, --gIntTargets ), vColUse, ALL_SIDES );
 if (gIntTargets) jump Loop;

}


default{

 state_entry(){
   gKeyOwner = llGetOwner();
   gChnDialog = (integer)("0xF" + llGetSubString( gKeyOwner, 1, 7 ));
   string  vStrTargetID = llGetObjectName();
   gIntTargets = llGetNumberOfPrims();
   @Loop;
     if (llGetLinkName( gIntTargets ) == vStrTargetID){
         gLstTargets += (list)gIntTargets;
     }
   if (~(--gIntTargets)) jump Loop;
   state sReady;
 }
 changed( integer vBitChanges ){
   if ((CHANGED_OWNER | CHANGED_LINK) & vBitChanges){
     llResetScript();
   }
 }

}

state sReady{

 state_entry(){
   gIdxPanel = 9;
 }
 touch_end( integer vIntTotal ){
   if (llDetectedKey( 0 ) == gKeyOwner){
     state sRunning;
   }
 }
 changed( integer vBitChanges ){
   if ((CHANGED_OWNER | CHANGED_LINK) & vBitChanges){
     state default;
   }
 }

}


state sRunning{

 state_entry(){
   llListen( gChnDialog, "", gKeyOwner, "" );
   fColorDialog();
 }
 listen( integer vIntChannel, string vStrName, key vKeySpeaker, string vStrHeard ){
    //-- get the index of the reply from our button list
   integer vIdxReply = llListFindList( gLstButtons, (list)vStrHeard );
    //-- is it a valid index? ~(-1) = FALSE
   if (~vIdxReply){
      //-- reply index 0 -5
     if (6 > vIdxReply){
        //-- get current color add change amount form dialog
       vector vColCalc = llGetColor( ALL_SIDES )
                         + llList2Vector( gLstBValues, gIdxPanel - 3 )
                         * llList2Float( gLstBValues, vIdxReply );
        //-- Clamp color values to [0, 1]
       fSetColor( <(0.0 < vColCalc.x && vColCalc.x < 1.0) * vColCalc.x,
                   (0.0 < vColCalc.y && vColCalc.y < 1.0) * vColCalc.y,
                   (0.0 < vColCalc.z && vColCalc.z < 1.0) * vColCalc.z>
                   + <(vColCalc.x >= 1.0),
                      (vColCalc.y >= 1.0),
                      (vColCalc.z >= 1.0)> );
      //-- reply index 6-8
     }else if (9 > vIdxReply){
        //-- Apply Saved Color
       if (6 == vIdxReply){
         fSetColor( gColDefault );
        //-- done, go back to waiting
       }else if (7 == vIdxReply){
         llSetTimerEvent( 0.0 );
         state sReady;
        //-- save current color
       }else{
         gColDefault = llGetColor( ALL_SIDES );
         llWhisper( 0, "Color saved." );
       }
      //-- reply index 9-12
     }else if (13 > vIdxReply){
      //-- change dialog panel
       gIdxPanel = vIdxReply;
     }
     fColorDialog();
   }
 }
 timer(){
    //-- timeout to kill listens
   llSetTimerEvent( 0.0 );
   llOwnerSay( gStrProduct + " Dialog Timed Out." );
   state sReady;
 }
 changed( integer vBitChanges ){
   if ((CHANGED_OWNER | CHANGED_LINK) & vBitChanges){
     state default;
   }
 }

}</lsl>

Return to top

Questions/Comments?

Feel free to leave me a note on my User Talk page.