Difference between revisions of "Rainbow palette"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<lsl>
<source lang="lsl2">
// Rainbow Palette by Rui Clary
// Rainbow Palette by Rui Clary
// This script will only run in Mono enabled, Second Life  Viewer 1.21 or above  
// This script will only run in Mono enabled, Second Life  Viewer 1.21 or above.
//
//
// Interactive Rainbow Palette
// Interactive Rainbow Palette
//
//
// Add this script to a cube prim and add "Listen Palete" script to another Object.
// Add this script to a cube prim and add "Listen Palete" script to another Object.
// You can resize and stretch the cube, the way you want, to make it look like a color palette.
// Touch face 1 of "Rainbow Palette" to change "Listen Object" color.
// Touch face 1 of "Rainbow Palette" to change "Listen Object" color.
//
//
// Modified by Rui Clary on 2011.06.20 - some corrections
// Available under the Creative Commons Attribution-ShareAlike 3.0 license
// Available under the Creative Commons Attribution-ShareAlike 3.0 license
// http://creativecommons.org/licenses/by-sa/3.0/
// http://creativecommons.org/licenses/by-sa/3.0/
Line 21: Line 23:
     touch(integer num_detected)  
     touch(integer num_detected)  
     {
     {
        float x;
        float x;
        float r;
        float r;
        float g;
        float g;
        float b;
        float b;
         vector touchedpos = llDetectedTouchST(0);   
         vector touchedpos = llDetectedTouchST(0);   
         if (llDetectedTouchFace(0)==1)
         if (llDetectedTouchFace(0)==1)
         {   
         {   
            x=360*touchedpos.x;
            x=360*touchedpos.x;
              
             r=0;
             if (x>=0&&x<=60)
             g=0;
                {r=255;}
            b=0;
             if(x>=300&&x<=360)
             if (x>=0&&x<=60){
                 {r=255;}
                 r=255;
            if (x>=120&&x<=240)
g=x*255/60;
                {r=0;}
            }
             if (x>60&&x<=120)
             if (x>60&&x<=120){
                 {r=255-(x-60)*255/60;}
                 r=255-(x-60)*255/60;
            if (x>240&&x<300)
                 g=255;
                 {r=(x-240)*255/60;}      
            }
             if (x>=0&&x<60)
             if (x>120&&x<=180){
                 {g=x*255/60;}   
                 g=255;
             if (x>=60&&x<=180)
                b=(x-120)*255/60;
                {g=255;}      
             }
             if (x>180&&x<240)
             if (x>180&&x<240){
                 {g=255-(x-180)*255/60;}       
                 g=255-(x-180)*255/60;
            if (x>=240&&x<=360)
                 b=255;
                 {g=0;}               
             }      
             if (x>=0&&x<=120)
             if (x>240&&x<300){
                {b=0;}  
                 r=(x-240)*255/60;
             if (x>120&&x<180)
                 b=255;
                 {b=(x-120)*255/60;}   
            }  
            if (x>=180&&x<=300)
             if (x>300&&x<=360){
                 {b=255;}      
                 r=255;
             if (x>300&&x<=360)
b=255-(x-300)*255/60;
                 {b=255-(x-300)*255/60;}   
            }   
                 llSay(4,"<"+(string)(r/255)+","+(string)(g/255)+","+(string)(b/255)+">");
                 llSay(4,"<"+(string)(r/255)+","+(string)(g/255)+","+(string)(b/255)+">");
         }
         }
Line 62: Line 64:
}
}


</lsl>
</source>


<lsl>
<source lang="lsl2">
// Rainbow Palette Listen Script by Rui Clary
// Rainbow Palette Listen Script by Rui Clary
// This script will only run in Mono enabled, Second Life  Viewer 1.21 or above
//
//
// Interactive Rainbow Palette
// Second component of Rainbow Palette  
//
// Add this script to  "Listen Object".
 
 
default
{
    state_entry()
    {
        llSetTexture ("5748decc-f629-461c-9a36-a35a221fe21f",ALL_SIDES);
        llListen( 4, "pal", NULL_KEY, "" );
    }
  listen( integer channel, string name, key id, string message )
    {
        llSetColor((vector)message,0);
    }
}
</source>
 
Modified version with fixed floats and "organized" :)
 
<source lang="lsl2">
// Bsed on Rainbow Palette by Rui Clary
//
// Modified by Jor3l Boa. Better interface and more readable :P
//
//
// Add this script to a cube prim and add "Listen Palete" script to another Object.
// Modified by Rui Clary on 2011.06.20 - some corrections
// Touch face 1 of "Rainbow Palette" to change "Listen Object" color.
//
//
// Available under the Creative Commons Attribution-ShareAlike 3.0 license
// Available under the Creative Commons Attribution-ShareAlike 3.0 license
// http://creativecommons.org/licenses/by-sa/3.0/
// http://creativecommons.org/licenses/by-sa/3.0/
// devolverString -> Convert and return a vector without .0000 and other
// float things :)
devolverString(float r, float g, float b) {
    string _vector = "<";
    if(r <= 0)  {
        _vector += "0,";
    }
    else if(r == 1) {
        _vector += "1,";
    }
    else    {
        string temp = (string)r;
        while(llGetSubString(temp,llStringLength(temp)-1,-1) == "0")    {
            temp = llDeleteSubString(temp,llStringLength(temp)-1,-1);
        }
        _vector += temp+",";
    }
    //----------------
    if(g <= 0)  {
        _vector += "0,";
    }
    else if(g == 1) {
        _vector += "1,";
    }
    else    {
        string temp = (string)g;
        while(llGetSubString(temp,llStringLength(temp)-1,-1) == "0")    {
            temp = llDeleteSubString(temp,llStringLength(temp)-1,-1);
        }
        _vector += temp+",";
    }
    //----------------
    if(b <= 0)  {
        _vector += "0>";
    }
    else if(b == 1) {
        _vector += "1>";
    }
    else    {
        string temp = (string)b;
        while(llGetSubString(temp,llStringLength(temp)-1,-1) == "0")    {
            temp = llDeleteSubString(temp,llStringLength(temp)-1,-1);
        }
        _vector += temp+">";
    }
    //----------------
    llSay(0,"Color: "+_vector);
}


default
default
Line 80: Line 153:
     state_entry()
     state_entry()
     {
     {
         llListen( 4, "pal", NULL_KEY, "" );  
         llSetObjectName("pal");
        llSetTexture ("5748decc-f629-461c-9a36-a35a221fe21f",ALL_SIDES);
        llSetTexture("5543eaa7-4283-8383-eef9-945c0b3f25c7",1);
     }
     }
  listen( integer channel, string name, key id, string message )
    touch_start(integer num_detected)  
     {
     {
         llSetColor((vector)message,0);
         float x;float r;float g;float b;
        vector touchedpos = llDetectedTouchST(0); 
       
        if(llDetectedTouchFace(0) != 1) { return;  }
        x=360*touchedpos.x;
        r=0;
        g=0;
        b=0;
        if (x>=0&&x<=60){
            r=255;
            g=x*255/60;
        }
        if (x>60&&x<=120){
            r=255-(x-60)*255/60;
            g=255;
        }
        if (x>120&&x<=180){
            g=255;
            b=(x-120)*255/60;
        }
        if (x>180&&x<240){
            g=255-(x-180)*255/60;
            b=255;
        }       
        if (x>240&&x<300){
            r=(x-240)*255/60;
            b=255;
        }   
        if (x>300&&x<=360){
            r=255;
            b=255-(x-300)*255/60;
        } 
        r = (r/255);
        g = (g/255);
        b = (b/255);
        //CONVERSION
        devolverString(r,g,b);
     }
     }
}
}
</lsl>
</source>
 
In order for the above script to work as the original some corrections should be added.
 
Replace:
<source lang="lsl2">
llSay(0,"Color: "+_vector);
</source>
 
with:
<source lang="lsl2">
llSay(4,_vector);
</source>
 
Replace:
<source lang="lsl2">touch_start</source>
 
with:
 
<source lang="lsl2">touch</source>

Latest revision as of 07:42, 25 January 2015

// Rainbow Palette by Rui Clary
// This script will only run in Mono enabled, Second Life  Viewer 1.21 or above.
//
// Interactive Rainbow Palette
//
// Add this script to a cube prim and add "Listen Palete" script to another Object.
// You can resize and stretch the cube, the way you want, to make it look like a color palette.
// Touch face 1 of "Rainbow Palette" to change "Listen Object" color.
//
// Modified by Rui Clary on 2011.06.20 - some corrections
// Available under the Creative Commons Attribution-ShareAlike 3.0 license
// http://creativecommons.org/licenses/by-sa/3.0/

default
{
    state_entry()
    {
        llSetObjectName("pal");
        llSetTexture ("5748decc-f629-461c-9a36-a35a221fe21f",ALL_SIDES);
        llSetTexture("5543eaa7-4283-8383-eef9-945c0b3f25c7",1);
    }
    touch(integer num_detected) 
    {
         float x;
         float r;
         float g;
         float b;
         vector touchedpos = llDetectedTouchST(0);  
         if (llDetectedTouchFace(0)==1)
         {  
            x=360*touchedpos.x;
            r=0;
            g=0;
            b=0;
            if (x>=0&&x<=60){
                r=255;
		g=x*255/60;
            }
            if (x>60&&x<=120){
                r=255-(x-60)*255/60;
                g=255;
            }
            if (x>120&&x<=180){
                g=255;
                b=(x-120)*255/60;
            }
            if (x>180&&x<240){
                g=255-(x-180)*255/60;
                b=255;
            }        
            if (x>240&&x<300){
                r=(x-240)*255/60;
                b=255;
            }    
            if (x>300&&x<=360){
                r=255;
		b=255-(x-300)*255/60;
            }  
                llSay(4,"<"+(string)(r/255)+","+(string)(g/255)+","+(string)(b/255)+">");
        }
    }
   
}
// Rainbow Palette Listen Script by Rui Clary
//
// Second component of Rainbow Palette 
//
// Add this script to  "Listen Object".


default
{
    state_entry()
    {
        llSetTexture ("5748decc-f629-461c-9a36-a35a221fe21f",ALL_SIDES);
        llListen( 4, "pal", NULL_KEY, "" ); 
    }
   listen( integer channel, string name, key id, string message )
    {
        llSetColor((vector)message,0);
    }
}

Modified version with fixed floats and "organized" :)

// Bsed on Rainbow Palette by Rui Clary
//
// Modified by Jor3l Boa. Better interface and more readable :P
//
// Modified by Rui Clary on 2011.06.20 - some corrections
//
// Available under the Creative Commons Attribution-ShareAlike 3.0 license
// http://creativecommons.org/licenses/by-sa/3.0/

// devolverString -> Convert and return a vector without .0000 and other
// float things :)
devolverString(float r, float g, float b) {
    string _vector = "<";
    if(r <= 0)  {
        _vector += "0,";
    }
    else if(r == 1) {
        _vector += "1,";
    }
    else    {
        string temp = (string)r;
        while(llGetSubString(temp,llStringLength(temp)-1,-1) == "0")    {
            temp = llDeleteSubString(temp,llStringLength(temp)-1,-1);
        }
        _vector += temp+",";
    }
    //----------------
    if(g <= 0)  {
        _vector += "0,";
    }
    else if(g == 1) {
        _vector += "1,";
    }
    else    {
        string temp = (string)g;
        while(llGetSubString(temp,llStringLength(temp)-1,-1) == "0")    {
            temp = llDeleteSubString(temp,llStringLength(temp)-1,-1);
        }
        _vector += temp+",";
    }
    //----------------
    if(b <= 0)  {
        _vector += "0>";
    }
    else if(b == 1) {
        _vector += "1>";
    }
    else    {
        string temp = (string)b;
        while(llGetSubString(temp,llStringLength(temp)-1,-1) == "0")    {
            temp = llDeleteSubString(temp,llStringLength(temp)-1,-1);
        }
        _vector += temp+">";
    }
    //----------------
    llSay(0,"Color: "+_vector);
}

default
{
    state_entry()
    {
        llSetObjectName("pal");
        llSetTexture ("5748decc-f629-461c-9a36-a35a221fe21f",ALL_SIDES);
        llSetTexture("5543eaa7-4283-8383-eef9-945c0b3f25c7",1);
    }
    touch_start(integer num_detected) 
    {
        float x;float r;float g;float b;
        vector touchedpos = llDetectedTouchST(0);   
        
        if(llDetectedTouchFace(0) != 1) { return;   }
        x=360*touchedpos.x;
        r=0;
        g=0;
        b=0;
        if (x>=0&&x<=60){
            r=255;
            g=x*255/60;
        }
        if (x>60&&x<=120){
            r=255-(x-60)*255/60;
            g=255;
        }
        if (x>120&&x<=180){
            g=255;
            b=(x-120)*255/60;
        }
        if (x>180&&x<240){
            g=255-(x-180)*255/60;
            b=255;
        }        
        if (x>240&&x<300){
            r=(x-240)*255/60;
            b=255;
        }    
        if (x>300&&x<=360){
            r=255;
            b=255-(x-300)*255/60;
        }  
        r = (r/255);
        g = (g/255);
        b = (b/255);
        //CONVERSION
        devolverString(r,g,b);
    }
 
}

In order for the above script to work as the original some corrections should be added.

Replace:

llSay(0,"Color: "+_vector);

with:

llSay(4,_vector);

Replace:

touch_start

with:

touch