Difference between revisions of "Color Cycle"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
Line 3: Line 3:
Cycles through color wheel at 15 degree intervals every second.
Cycles through color wheel at 15 degree intervals every second.


<lsl>
<source lang="lsl2">
// Cycle color each second for every 15 degress around the color wheel
// Cycle color each second for every 15 degress around the color wheel
// @author: JB Kraft
// @author: JB Kraft
Line 61: Line 61:
}
}


</lsl>
</source>


Below Added by Nephilim jinx:
Below Added by Nephilim jinx:
Line 67: Line 67:
You can also make use of this by adding the "if" statement to detect owner only and reset on rez for builds.
You can also make use of this by adding the "if" statement to detect owner only and reset on rez for builds.


<lsl>
<source lang="lsl2">
// Cycle color each second for every 15 degress around the color wheel
// Cycle color each second for every 15 degress around the color wheel
// @author: JB Kraft
// @author: JB Kraft
Line 129: Line 129:
     }
     }
}
}
</lsl>
</source>


and to expand even more. the tags could be simply set from ALL_SIDES to a specific side number!
and to expand even more. the tags could be simply set from ALL_SIDES to a specific side number!


<lsl>
<source lang="lsl2">


     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
Line 145: Line 145:
     }
     }
}
}
</lsl>
</source>


but lets go one step further. you would want multiple sides of one prim but not all sides, simply replicate llSetColor like so.
but lets go one step further. you would want multiple sides of one prim but not all sides, simply replicate llSetColor like so.


<lsl>
<source lang="lsl2">
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     timer( )
     timer( )
Line 162: Line 162:
     }
     }
}
}
</lsl>
</source>


and for those builders who like to make multiple objects sync the same color in cyclic order. the messaged link can be added to the touch event like the following.
and for those builders who like to make multiple objects sync the same color in cyclic order. the messaged link can be added to the touch event like the following.
(THIS IS FOR THE MASTER/ROOT PRIM SCRIPT AND SHOULD NOT BE USED IN SLAVE/CHILD PRIM SCRIPT!)
(THIS IS FOR THE MASTER/ROOT PRIM SCRIPT AND SHOULD NOT BE USED IN SLAVE/CHILD PRIM SCRIPT!)


<lsl>
<source lang="lsl2">
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     touch_start(integer a)
     touch_start(integer a)
Line 180: Line 180:
}
}
     }
     }
</lsl>
</source>


and for the child/slave prim script we would replace the touch event with a listen instead!
and for the child/slave prim script we would replace the touch event with a listen instead!
(THIS IS FOR THE CHILD/SLAVE PRIM SCRIPT AND SHOULD NOT BE USED IN MASTER/ROOT PRIM!)
(THIS IS FOR THE CHILD/SLAVE PRIM SCRIPT AND SHOULD NOT BE USED IN MASTER/ROOT PRIM!)


<lsl>
<source lang="lsl2">
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
link_message(integer sender_num, integer num, string str, key id)
link_message(integer sender_num, integer num, string str, key id)
Line 194: Line 194:
         llSetTimerEvent( g_TIMER );
         llSetTimerEvent( g_TIMER );
     }
     }
  </lsl>
  </source>
[[Category:LSL Examples]]
[[Category:LSL Examples]]

Latest revision as of 13:19, 24 January 2015

Cycle through the color wheel

Cycles through color wheel at 15 degree intervals every second.

// Cycle color each second for every 15 degress around the color wheel
// @author: JB Kraft
// ------------------------------------------------------------------------
// Jan 28, 2007 - v0.1 orig example code
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// 24 color values, one for each 15 degrees around the color wheel
list realcolors = [
<1.000000, 0.000000, 0.000000>, <1.000000, 0.200000, 0.000000>, 
<1.000000, 0.400000, 0.000000>, <1.000000, 0.501961, 0.000000>, 
<1.000000, 0.600000, 0.000000>, <1.000000, 0.698039, 0.000000>, 
<1.000000, 0.800000, 0.000000>, <1.000000, 0.898039, 0.000000>, 
<1.000000, 1.000000, 0.000000>, <0.800000, 1.000000, 0.000000>, 
<0.200000, 1.000000, 0.000000>, <0.000000, 0.800000, 0.000000>, 
<0.000000, 0.698039, 0.400000>, <0.000000, 0.600000, 0.600000>, 
<0.000000, 0.400000, 0.698039>, <0.000000, 0.200000, 0.800000>, 
<0.098039, 0.098039, 0.698039>, <0.200000, 0.000000, 0.600000>, 
<0.250980, 0.000000, 0.600000>, <0.400000, 0.000000, 0.600000>, 
<0.600000, 0.000000, 0.600000>, <0.800000, 0.000000, 0.600000>, 
<0.898039, 0.000000, 0.400000>];

// keep time
integer g_TIMER = 0;
// the offset into the color array
integer g_NDX = 0;

// ------------------------------------------------------------------------
// D E F A U L T
// ------------------------------------------------------------------------
default
{
    // --------------------------------------------------------------------
    state_entry()
    {
    }

    // --------------------------------------------------------------------
    touch_start(integer total_number)
    {
        // turn the timer on/off        
        g_TIMER = !g_TIMER;
        // cheeky use of flag as timer value
        llSetTimerEvent( g_TIMER );
    }
    
    
    // --------------------------------------------------------------------
    timer( )
    {
        if( g_NDX > llGetListLength( realcolors ) - 1) {
            g_NDX = 0;
        }
        llSetColor( llList2Vector( realcolors, g_NDX), ALL_SIDES );
        ++g_NDX;
    }
}

Below Added by Nephilim jinx:

You can also make use of this by adding the "if" statement to detect owner only and reset on rez for builds.

// Cycle color each second for every 15 degress around the color wheel
// @author: JB Kraft
// @edit by: Nephilim Jinx
// ------------------------------------------------------------------------
// April, 29 2012 Edit
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
// 24 color values, one for each 15 degrees around the color wheel
list realcolors = [
<1.000000, 0.000000, 0.000000>, <1.000000, 0.200000, 0.000000>, 
<1.000000, 0.400000, 0.000000>, <1.000000, 0.501961, 0.000000>, 
<1.000000, 0.600000, 0.000000>, <1.000000, 0.698039, 0.000000>, 
<1.000000, 0.800000, 0.000000>, <1.000000, 0.898039, 0.000000>, 
<1.000000, 1.000000, 0.000000>, <0.800000, 1.000000, 0.000000>, 
<0.200000, 1.000000, 0.000000>, <0.000000, 0.800000, 0.000000>, 
<0.000000, 0.698039, 0.400000>, <0.000000, 0.600000, 0.600000>, 
<0.000000, 0.400000, 0.698039>, <0.000000, 0.200000, 0.800000>, 
<0.098039, 0.098039, 0.698039>, <0.200000, 0.000000, 0.600000>, 
<0.250980, 0.000000, 0.600000>, <0.400000, 0.000000, 0.600000>, 
<0.600000, 0.000000, 0.600000>, <0.800000, 0.000000, 0.600000>, 
<0.898039, 0.000000, 0.400000>];
 
// keep time
integer g_TIMER = 0;
// the offset into the color array
integer g_NDX = 0;
 
// ------------------------------------------------------------------------
// D E F A U L T
// ------------------------------------------------------------------------
default
{
    // --------------------------------------------------------------------
    on_rez(integer start_param)
    {
    llResetScript();
    }
 
    // --------------------------------------------------------------------
    touch_start(integer a)
    {
    if(llDetectedKey(0) == llGetOwner())
{
        // turn the timer on/off        
        g_TIMER = !g_TIMER;
        // cheeky use of flag as timer value
        llSetTimerEvent( g_TIMER );
}
    }
 
 
    // --------------------------------------------------------------------
    timer( )
    {
        if( g_NDX > llGetListLength( realcolors ) - 1) {
            g_NDX = 0;
        }
        llSetColor( llList2Vector( realcolors, g_NDX), ALL_SIDES);
        ++g_NDX;
    }
}

and to expand even more. the tags could be simply set from ALL_SIDES to a specific side number!

    // --------------------------------------------------------------------
    timer( )
    {
        if( g_NDX > llGetListLength( realcolors ) - 1) {
            g_NDX = 0;
        }
        llSetColor( llList2Vector( realcolors, g_NDX), 2);
        ++g_NDX;
    }
}

but lets go one step further. you would want multiple sides of one prim but not all sides, simply replicate llSetColor like so.

    // --------------------------------------------------------------------
    timer( )
    {
        if( g_NDX > llGetListLength( realcolors ) - 1) {
            g_NDX = 0;
        }
        llSetColor( llList2Vector( realcolors, g_NDX), 1);
        llSetColor( llList2Vector( realcolors, g_NDX), 2);
        llSetColor( llList2Vector( realcolors, g_NDX), 3);
        ++g_NDX;
    }
}

and for those builders who like to make multiple objects sync the same color in cyclic order. the messaged link can be added to the touch event like the following. (THIS IS FOR THE MASTER/ROOT PRIM SCRIPT AND SHOULD NOT BE USED IN SLAVE/CHILD PRIM SCRIPT!)

    // --------------------------------------------------------------------
    touch_start(integer a)
    {
    if(llDetectedKey(0) == llGetOwner())
{
        // turn the timer on/off        
        g_TIMER = !g_TIMER;
        // cheeky use of flag as timer value
        llMessageLinked(LINK_SET, 0, "Touched.", NULL_KEY);
        llSetTimerEvent( g_TIMER );
}
    }

and for the child/slave prim script we would replace the touch event with a listen instead! (THIS IS FOR THE CHILD/SLAVE PRIM SCRIPT AND SHOULD NOT BE USED IN MASTER/ROOT PRIM!)

    // --------------------------------------------------------------------
link_message(integer sender_num, integer num, string str, key id)
 {
        // turn the timer on/off        
        g_TIMER = !g_TIMER;
        // cheeky use of flag as timer value
        llSetTimerEvent( g_TIMER );
    }