Change font size
It is currently Tue Jul 17, 2018 11:32 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 1 post ]
Author Message
 Post subject: "Fade to any color" script
PostPosted: Mon Aug 25, 2008 12:54 pm 
Furious Typer
User avatar

Joined: Sat Feb 02, 2008 10:02 pm
Posts: 104
Location: Romania, Bucharest
This is a script made by godfrey which can transit the color on a primitive to a given color, no matter what the primitive's current color is. I thought it may be of use to other people too so here it is:

{L_CODE}:
integer OwnerControlOnly = 1;  // Set to 1 if only the owner should control it, or 0 if anyone can control it.

integer ListenChannel = 1;  // Channel upon which to listen.  Nonzero is preferable to reduce lag,
                            //  but this will require that you specify a channel to control the script.
                            //  For example:  /1 red

float NumberOfSteps = 10.0;  // number of intermediate colors the transition will go through (even though this
                             //  is a float, it should be an integer value (i.e. end in .0)

float TimerTick  = 0.1;      // number of seconds between color change steps

// ============================= internal variables below, do not change =======================================

vector CurrentColor;
vector TargetColor;
vector Delta;
integer StepCount;

ProvideHelp( key whom )
{
    llInstantMessage( whom, "Usage: /" + (string) ListenChannel + " {red|green|blue|yellow|cyan|magenta|orange|black|white|grey}" );
}

Change( vector target )
{
    TargetColor = target;
    Delta = (TargetColor - CurrentColor) / NumberOfSteps;
    StepCount = 0;
    llSetTimerEvent( TimerTick );
}

default
{
    state_entry()
    {
        if (OwnerControlOnly)
        {
            llListen( 1, "", llGetOwner(), "" );
        }
        else
        {
            llListen( 1, "", "", "" );
        }
        CurrentColor = <1.0,0.0,0.0>; // start off as red
        llSetColor( CurrentColor, ALL_SIDES );
    }
   
    changed( integer whatChanged )
    {
        if (whatChanged & (256 | CHANGED_OWNER)) llResetScript();
    }
   
    listen( integer channel, string whoSpoke, key speakerID, string message )
    {
        message = llToLower( message );
        if (message == "red")           Change( <1.0,0.0,0.0> );
        else if (message == "green")    Change( <0.0,1.0,0.0> );
        else if (message == "blue")     Change( <0.0,0.0,1.0> );
        else if (message == "yellow")   Change( <1.0,1.0,0.0> );
        else if (message == "cyan")     Change( <0.0,1.0,1.0> );
        else if (message == "magenta")  Change( <1.0,0.0,1.0> );
        else if (message == "orange")   Change( <1.0,0.5,0.0> );
        else if (message == "black")    Change( <0.0,0.0,0.0> );
        else if (message == "white")    Change( <1.0,1.0,1.0> );
        else if (message == "grey")     Change( <0.5,0.5,0.5> );
        else ProvideHelp( speakerID );
    }
   
    timer()
    {
        if (++StepCount >= NumberOfSteps)
        {
            llSetColor( TargetColor, ALL_SIDES );
            llSetTimerEvent( 0.0 );
            StepCount = 0;
        }
        else
        {
            CurrentColor += Delta;
            llSetColor( CurrentColor, ALL_SIDES );
        }
    }
}


Alternatively, I made a much simpler version to use between the scripts I needed with only the simple color fading feature. If anyone wants it, this is my modified version:

{L_CODE}:
float NumberOfSteps = 10.0;
float TimerTick = 0.1;

vector CurrentColor;
vector TargetColor;
vector Delta;
integer StepCount;

Change(vector target)
{
    TargetColor = target;
    Delta = (TargetColor - CurrentColor) / NumberOfSteps;
    StepCount = 0;
    llSetTimerEvent(TimerTick);
}

default
{
    state_entry()
    {
        llListen(1,"",NULL_KEY,"");
        CurrentColor = llGetColor(1);
    }

    listen(integer channel, string name, key id, string message)
    {
        message = llToLower(message);
        if (message == "red")      Change(<1,0,0>);
        if (message == "green")    Change(<0,1,0>);
        if (message == "blue")     Change(<0,0,1>);
        if (message == "yellow")   Change(<1,1,0>);
        if (message == "cyan")     Change(<0,1,1>);
        if (message == "magenta")  Change(<1,0,1>);
        if (message == "orange")   Change(<1,0.5,0>);
        if (message == "black")    Change(<0,0,0>);
        if (message == "white")    Change(<1,1,1>);
        if (message == "grey")     Change(<0.5,0.5,0.5>);
    }
   
    timer()
    {
        if (++StepCount >= NumberOfSteps)
        {
            llSetColor(TargetColor, ALL_SIDES);
            llSetTimerEvent(0);
            StepCount = 0;
        }
        else
        {
            CurrentColor += Delta;
            llSetColor(CurrentColor, ALL_SIDES);
        }
    }
}


Note: If you set the color manually on the prim the script may attempt to jump to another color first then start fading. Otherwise it's a really good script.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 1 post ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net