Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

color fading NOT on command

Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
05-05-2008 14:32
Hey all I have this nifty script - superb, except I dont want to tell it to do anything I just want it to do it. I tried hacking my way through it removing the listens and toggles because all I want is it to automagically fade from red to blue to black (rinse repeat) and nothing else. Can anyone point me in the right direction of what NOT to touch and what is good to whack away?

CODE

Thanks to Ksharra Manimal for finding a bug, here's the updated version:

CODE
// linkset color variation over time
// can be random or sequential in hue
// random is NOT advised as it strains the Sim's resources

// Author: Jesrad Seraph
// use, modify and redistribute freely


// commands:
// /23 toggle => toggles between sequential and random color change
// /23 reset => sets color back to pure red, useful to sync multiple items
// /23 start => starts the color change effect
// /23 stop => freezes the color change effect
// /23 clear => stops the effect and sets color to white
// /23 blue => stops the effect and sets color to pure blue
// /23 green => stops the effect and sets color to pure green
// /23 red => stops the effect and sets color to pure red
// /23 saturate => augments the saturation up 10%
// /23 desaturate => decreases saturation by 10%
// /23 faster => makes the effect twice as fast (WARNING may cause lag on the whole Sim at high speeds)
// /23 slower => makes the effect half as fast
// /23 alpha => makes the object 10% more transparent
// /23 dealpha => makes the object 10% less transparent
// /23 transparent => makes the object fully transparent
// /23 opaque => makes the object fully opaque
// /23 change => manually triggers the color change
// saturation control only affects the sequential fade effect

key owner;

integer ISSEQUENTIAL = 1;

integer listen_handle;

float colordelay = 2.0;
// this is the default color update frequency

float unsaturation = 0.0;
float opacity = 1.0;

vector currentcolor = <1.0, 0.0, 0.0>;
// switch to pure red on reset

integer currentangle = 0;
integer currentdir = 0;
// 0 for red to green
// 1 for green to blue
// 2 for blue to red

integer angle_increment = 3;
// determines the number of steps around the hue wheel.
// the lower the more steps, doesn't go over 90
// Always use a factor of 90 for better results
// 3 or 5 are good values



colorupdate()
{
// change current color
if (ISSEQUENTIAL < 0)
{
// set a random color:
currentcolor = <llFrand(1),llFrand(1),llFrand(1)>;
}
else
{
// rotate the color vector along X Y Z to vary between red, green and blue
if (currentangle >= 90)
{
currentdir += 1;
currentangle = 0;
if ((currentdir >= 3) || (currentdir < 0))
currentdir = 0;
}
currentangle += angle_increment;
}
}

colorchange()
{
float float_angle = ((float)currentangle) * DEG_TO_RAD;
float sinelement = llSin(float_angle) * (1.0 - unsaturation) + unsaturation;
float coselement = llCos(float_angle) * (1.0 - unsaturation) + unsaturation;

if (ISSEQUENTIAL > 0)
{
if (currentdir == 0)
{
currentcolor = <coselement, sinelement, unsaturation>;
}
else if (currentdir == 1)
{
currentcolor = <unsaturation, coselement, sinelement>;
}
else if (currentdir == 2)
{
currentcolor = <sinelement, unsaturation, coselement>;
}
}

llSetColor(currentcolor,ALL_SIDES);
llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
}

default
{
state_entry()
{
llListenRemove(listen_handle);
owner=llGetOwner();
listen_handle = llListen(23,"",owner,"");
}

timer()
{
colorupdate();
colorchange();
}

listen(integer channel, string name, key id, string message)
{
if (message == "toggle")
{
ISSEQUENTIAL *= -1;
}
else if (message == "reset")
{
currentcolor = <1.0, 0.0, 0.0>;
unsaturation = 0.0;
currentangle = 0;
currentdir = 0;
ISSEQUENTIAL = 1;
colordelay = 2.0;
llSetColor(currentcolor,ALL_SIDES);
llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
llSetTimerEvent(colordelay);
}
else if (message == "start")
{
llSetTimerEvent(colordelay);
}
else if (message == "stop")
{
llSetTimerEvent(0);
}
else if (message == "clear")
{
llSetTimerEvent(0);
currentcolor = <1.0, 1.0, 1.0>;
llSetColor(currentcolor,ALL_SIDES);
llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
}
else if (message == "blue")
{
llSetTimerEvent(0);
unsaturation = 0.0;
currentangle = 0;
currentdir = 2;
colorchange();
}
else if (message == "green")
{
llSetTimerEvent(0);
unsaturation = 0.0;
currentangle = 0;
currentdir = 1;
colorchange();
}
else if (message == "red")
{
llSetTimerEvent(0);
unsaturation = 0.0;
currentangle = 0;
currentdir = 0;
colorchange();
}
else if (message == "black")
{
llSetTimerEvent(0);
currentcolor = <0.0, 0.0, 0.0>;
llSetColor(currentcolor,ALL_SIDES);
llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
}
else if (message == "faster")
{
colordelay /= 2.0;
if (colordelay < 0.25)
colordelay = 0.25;
llSetTimerEvent(colordelay);
}
else if (message == "slower")
{
colordelay *= 2.0;
llSetTimerEvent(colordelay);
}
else if (message == "saturate")
{
unsaturation -= 0.1;
if (unsaturation < 0.0)
unsaturation = 0.0;
colorchange();
}
else if (message == "desaturate")
{
unsaturation += 0.1;
if (unsaturation > 1.0)
unsaturation = 1.0;
colorchange();
}
else if (message == "alpha")
{
opacity -= 0.1;
if (opacity < 0.0)
opacity = 0.0;
llSetAlpha(opacity, ALL_SIDES);
llMessageLinked(LINK_SET,106,(string)opacity,NULL_ KEY);
}
else if (message == "dealpha")
{
opacity += 0.1;
if (opacity > 1.0)
opacity = 1.0;
llSetAlpha(opacity, ALL_SIDES);
llMessageLinked(LINK_SET,106,(string)opacity,NULL_ KEY);
}
else if (message == "transparent")
{
opacity = 0.0;
llSetAlpha(opacity, ALL_SIDES);
llMessageLinked(LINK_SET,106,(string)opacity,NULL_ KEY);
}
else if (message == "opaque")
{
opacity = 1.0;
llSetAlpha(opacity, ALL_SIDES);
llMessageLinked(LINK_SET,106,(string)opacity,NULL_ KEY);
}
else if (message == "change")
{
colorupdate();
colorchange();
}
}
}
_____________________
Every second of your life is a moment of opportunity to make it better than the last...
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
05-05-2008 14:58
This is what I have, I know its reading the state entry and the timer and the subsequent lines, but apparently it doesnt for some reason know what those lines mean...


CODE

float unsaturation = 0.0;
vector currentcolor = <1.0, 0.0, 0.0>;
// switch to pure red on reset

integer currentangle = 0;
integer currentdir = 0;
// 0 for red to green
// 1 for green to blue
// 2 for blue to red

integer angle_increment = 3;
// determines the number of steps around the hue wheel.
// the lower the more steps, doesn't go over 90
// Always use a factor of 90 for better results
// 3 or 5 are good values



colorupdate()
{
// rotate the color vector along X Y Z to vary between red, green and blue
if (currentangle >= 90)
{
currentdir += 1;
currentangle = 0;
if ((currentdir >= 3) || (currentdir < 0))
currentdir = 0;
}
currentangle += angle_increment;
}


colorchange()
{
float float_angle = ((float)currentangle) * DEG_TO_RAD;
float sinelement = llSin(float_angle) * (1.0 - unsaturation) + unsaturation;
float coselement = llCos(float_angle) * (1.0 - unsaturation) + unsaturation;

}

default
{
state_entry()
{

llSetTimerEvent(2.0);

}
timer()

{
colorupdate();

colorchange();

}
}



I thought that if I just defined what the color update and color change were then set the timer, off it would go on its merry way?
_____________________
Every second of your life is a moment of opportunity to make it better than the last...
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
yay me.
05-05-2008 15:26
It never fails that when I bang my head really hard and ask for help I figure it out...now whether or not its right or not is entirely another matter - and I wanted it to fade to black as the ending color so erm yeah (even tho I have changed the vector on reset to black hmmmm) but hey I got the first part yay me!

CODE

integer ISSEQUENTIAL = 1;

integer listen_handle;

float colordelay = 2.0;
// this is the default color update frequency

float unsaturation = 0.0;
float opacity = 1.0;

vector currentcolor = <0.0, 0.0, 0.0>;
// switch to pure black on reset....I SAID BLACK ARGGGH!

integer currentangle = 0;
integer currentdir = 0;
// 0 for red to green
// 1 for green to blue
// 2 for blue to red

integer angle_increment = 3;
// determines the number of steps around the hue wheel.
// the lower the more steps, doesn't go over 90
// Always use a factor of 90 for better results
// 3 or 5 are good values



colorupdate()
{
// change current color
if (ISSEQUENTIAL < 0)
{
// set a random color:
currentcolor = <llFrand(1),llFrand(1),llFrand(1)>;
}
else
{
// rotate the color vector along X Y Z to vary between red, green and blue
if (currentangle >= 90)
{
currentdir += 1;
currentangle = 0;
if ((currentdir >= 3) || (currentdir < 0))
currentdir = 0;
}
currentangle += angle_increment;
}
}

colorchange()
{
float float_angle = ((float)currentangle) * DEG_TO_RAD;
float sinelement = llSin(float_angle) * (1.0 - unsaturation) + unsaturation;
float coselement = llCos(float_angle) * (1.0 - unsaturation) + unsaturation;

if (ISSEQUENTIAL > 0)
{
if (currentdir == 0)
{
currentcolor = <coselement, sinelement, unsaturation>;
}
else if (currentdir == 1)
{
currentcolor = <unsaturation, coselement, sinelement>;
}
else if (currentdir == 2)
{
currentcolor = <sinelement, unsaturation, coselement>;
}
}

llSetColor(currentcolor,ALL_SIDES);
llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
}

default
{
state_entry()
{
llSetTimerEvent(colordelay);
}

timer()
{
colorupdate();
colorchange();
}

}
_____________________
Every second of your life is a moment of opportunity to make it better than the last...
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
05-05-2008 16:39
can someone tell me where these

integer currentangle = 0;
integer currentdir = 0;
// 0 for red to green
// 1 for green to blue
// 2 for blue to red


are defined? Is that something that is hard coded somewhere? 0 is always red to green, 1 blue to red and so on?


I managed to get black in there by changing currentangle += angle_increment; to currentangle -= angle_increment;, and I am quite sure I didnt do it correctly, so if any one has a moment to look it over and make sure I am not going to crash any sims that would be really great! XD

CODE

integer ISSEQUENTIAL = 1;

integer listen_handle;

float colordelay = 0.5;
// this is the default color update frequency

float unsaturation = 0;
float opacity = 1.0;

vector currentcolor = <0.0, 0.0, 0.0>;
// switch to pure red on reset

integer currentangle = 0;
integer currentdir = 2;
// 0 for red to green
// 1 for green to blue
// 2 for blue to red

integer angle_increment = 3;
// determines the number of steps around the hue wheel.
// the lower the more steps, doesn't go over 90
// Always use a factor of 90 for better results
// 3 or 5 are good values



colorupdate()
{
// change current color
if (ISSEQUENTIAL < 0)
{
// set a random color:
currentcolor = <llFrand(1),llFrand(1),llFrand(1)>;
}
else
{
// rotate the color vector along X Y Z to vary between red, green and blue
if (currentangle >= 90)
{
currentdir += 1;
currentangle = 0;
if ((currentdir >= 3) || (currentdir < 0))
currentdir = 0;
}
currentangle -= angle_increment;
}
}

colorchange()
{
float float_angle = ((float)currentangle) * DEG_TO_RAD;
float sinelement = llSin(float_angle) * (1.0 - unsaturation) - unsaturation;
float coselement = llCos(float_angle) * (1.0 - unsaturation) - unsaturation;

if (ISSEQUENTIAL > 0)
{
if (currentdir == 0)
{
currentcolor = <coselement, sinelement, unsaturation>;
}
else if (currentdir == 1)
{
currentcolor = <unsaturation, coselement, sinelement>;
}
else if (currentdir == 2)
{
currentcolor = <sinelement, unsaturation, coselement>;
}
}

llSetColor(currentcolor,ALL_SIDES);
llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
}

default
{
state_entry()
{
llSetTimerEvent(colordelay);
}

timer()
{
colorupdate();
colorchange();
}

}
_____________________
Every second of your life is a moment of opportunity to make it better than the last...