Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Strange...! Another Color Changing Script :)

Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
08-26-2005 22:47
Howdy all! Still rather new and getting my feet about me with scripting, but getting there. I'm working on a color changing script... pretty simple at least in concept, lol. Just want it to slowly cycles through the RBG range. I believe I got everything figured out expect the math part.

Here's the jist... script gets the color of the prim.. if it's 1,1,1, I want it to adjust the R down by .01. Then it's just looping back through if's til the R is at 0.0... then adjust the R back up by .1 and the G down by .01.

Sooo.. I got the if's down and all I believe. Just need help with those two lines that would change one color value, and not the others.

Would greatly appreciate any help with this! Figuring it's pretty simple, just beyond my reach so far, hehehe! Thanks!
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-26-2005 22:58
You can access individual elements of a vector like so:

vector.x for the first value,
vector.y for the second, and
vector.z for the last.

:)
_____________________
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
08-26-2005 23:56
Ok great! That's part of what I was looking for, thank you! I'd like to see a line of script actually though, because I'm not sure how to do the subtraction part in code.

Assuming it'd be something along the lines of...

color = (vector.x, -.01);

Given the color vectors already set etc.

That's pretty much a wild shot in the dark, lemme know! Thanks!
a lost user
Join date: ?
Posts: ?
08-26-2005 23:56
Color Changer Scripts...

...The new Hello World script? :D


vector prim_color = llGetColor(ALL_SIDES);

ok.. so you have a vector containing the mean color of the prim; prim_color.x is the RED value, prim_color.y is the GREEN value, and prim_color.z is the BLUE value.

prim_color = <1.0,0.5,0.25>;

....Is the same as...

prim_color.x = 1.0; // 100% or 255 Red
prim_color.y = 0.5; // 50% or 127 Green
prim_color.z = 0.25; // 25% or 63 Blue

while(prim_color.x > 0)
{
prim_color.x -= 0.1;
}

You can use a vector as a quicky float list.. etc etc
a lost user
Join date: ?
Posts: ?
Having fun with color :P
08-27-2005 01:00
Here's some fun things to demonstrate colors as a vector:

First, let's set up some color vectors and use them to subtract colors from other colors:
CODE

// Primary colors of light
vector red = <1,0,0>;
vector green = <0,1,0>;
vector blue = <0,0,1>;

// Secondary color of light
vector yellow = <1,1,0>;
vector magenta = <1,0,1>;
vector cyan = <0,1,1>;

// Black and white
vector black = <0,0,0>;
vector white = <1,1,1>;

// A list of the vectors for easier processing.
// It would have been better to create JUST the list but since this is an example
// I used this long, memory-hogging method.
list colors = [red,green,blue,yellow,magenta,cyan,black,white];

default
{
state_entry()
{
llSetColor(white,ALL_SIDES);
total_colors = llGetListLength(colors);
llSetTimerEvent(1.0);
}

timer()
{
count++;
if(count == total_colors) count = 0;
llSetColor(white - llList2Vector(colors,count),ALL_SIDES);
}
}


Watch what happens as the script runs.. if you take yellow (<1,1,0>;) from white (<1,1,1>;), you end up with blue (<0,0,1>;). Interesting?.. perhaps not.. anyway.. something else that is fun is making a color based on an unrelated vector, such as the object's position in the sim...

CODE

vector color;
float norm_color;

default
{
state_entry()
{
norm_color = (1.0 / 256);
color = llGetPos() * norm_color;
llSetColor(color,ALL_SIDES);
llSetTimerEvent(1.0);
}

timer()
{
color = llGetPos() * norm_color;
llSetColor(color,ALL_SIDES);
}
}


I may have got that calculation wrong.. but the idea is that a sim is made up of 256 x 256 meters, and at least 256 meters in height. So just convert that position vector into the color value. As the object moves around the sim, it will change color.

Have fun! :p
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
Awsome! Thanks!
08-27-2005 04:07
Great, thank you everyone! Some cool ideas there :)

Gonna take me a bit to chew it all up and spit it back out, but that's what I needed! Appreciate the help and the great explanaitions.
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
Here's my go...
08-27-2005 11:45
Alright, here's what I got. Already spotted some stuff that doesn't need to be in there, but I had it there at first when I was making my first attempt.

integer face = 1;
vector color = <1,1,1>;
integer side = ALL_SIDES;

default
{
state_entry()
{
llSetColor(<1,1,1>,ALL_SIDES);
state loop;
}

on_rez (integer start_param)
{
llResetScript();
}
}

state loop
{
state_entry()
{
llGetColor(face);
{
if(color == <1,1,1>;)
{
color.x -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x > .0 & color.y == 1.0 & color.z == 1.0)
{
color.x -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x == .0 & color.y == 1.0 & color.z == 1.0)
{
color.x += .01;
color.y -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x <= .99 & color.y > .0 & color.z == 1.0)
{
color.x += .01;
color.y -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x == 1.0 & color.y == .0 & color.z == 1.0)
{
color.y += .01;
color.z -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x == 1.0 & color.y <= .99 & color.z > .0)
{
color.y += .01;
color.z -= .01;
llSetColor(color,ALL_SIDES);
}
else while (color.x == 1.0 & color.y == 1.0 & color.z >= .0)
{
color.z += .01;
llSetColor(color,ALL_SIDES);
}
}
state loop;
}
}




Ok, I have a feeling there's a much easier way.. but that's what I figured should work... but it's not doing a thing to it.. at all, lol. It compiled alright.. but know that doesn't mean alot. Any ideas? Thanks!

Oh.. and I would have like to have put that in a window like above, but no idea how. Sorry!
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
Maybe...
08-27-2005 12:32
Been thinking on it... am I having a problem with the script re-entering the loop state? Meaning will the state_entry activate since I'm entering loop from loop?

Either that, or do I need lines in there storing the new color vectors again?

Couple of thoughts anywho. You all have been a terrific help so far! Thanks again :)
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-27-2005 12:43
since you're not actually reentering the state on that last state loop;, the state_entry() event doesn't get called.

I'd do this:

CODE
state loop
{
state_entry()
{
llSetTimerEvent(1.0);
}

timer()
{
color = llGetColor(face);

if(color == <1,1,1>)
{
color.x -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x > .0 & color.y == 1.0 & color.z == 1.0)
{
color.x -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x == .0 & color.y == 1.0 & color.z == 1.0)
{
color.x += .01;
color.y -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x <= .99 & color.y > .0 & color.z == 1.0)
{
color.x += .01;
color.y -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x == 1.0 & color.y == .0 & color.z == 1.0)
{
color.y += .01;
color.z -= .01;
llSetColor(color,ALL_SIDES);
}
else if(color.x == 1.0 & color.y <= .99 & color.z > .0)
{
color.y += .01;
color.z -= .01;
llSetColor(color,ALL_SIDES);
}
else while (color.x == 1.0 & color.y == 1.0 & color.z >= .0)
{
color.z += .01;
llSetColor(color,ALL_SIDES);
}
}
}
_____________________
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
*Cheers!*
08-27-2005 15:09
Awsome, thank you Jillian, that worked like a charm! Glad to know I'm getting the swing of this a little at least :) You all are the best, thank you!
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
Or.... not.
08-27-2005 19:55
Ok, looked great! Was working perfect until I noticed it was stuck on yellow. Looks like for some reason that it is not taking the last two lines of code, or getting stuck there, when trying to add the color.z back in...

Is there some other usage of else I should be using on the last command?

Thanks again everyone in advance! The script is still just like above, but with the timer event added.
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
Nevermind!
08-27-2005 20:01
LOL, nevermind. After a few hours of working on it, figured it out right after posting.

Simply made the last else just an else... assuming it was continuing looking for another option and not running the last line instead.

*salutes!*

Thanks!
Markubis Brentano
Hi...YAH!!
Join date: 15 Apr 2006
Posts: 836
07-14-2006 08:17
ok, I'm digging this post out of the past to ask a question on it. I got this color changer to work very nicely....including the issue mentioned about it getting stuck on yellow.

As you can see, I'm fairly new and am just learning the scripting language.

The problem I'm having with it now is that after some running, it eventually just stops. My only guess is that it finally reaches the starting color again and stops?

I would like it to run infinately if possible and would appreciate any help by the experienced scripters in this forum.



Any help would be appreciated. thanks
Ohforf Uram
n00b
Join date: 27 Jun 2006
Posts: 82
07-14-2006 09:05
I guess the last loop runs forever
CODE

else while (color.x == 1.0 & color.y == 1.0 & color.z >= .0)
{
color.z += .01;
llSetColor(color,ALL_SIDES);
}
Ohforf Uram
n00b
Join date: 27 Jun 2006
Posts: 82
07-14-2006 10:44
Another Colorchanger :

CODE

float delay=1.0;
float step=0.1;
vector col=<0,0,step>;
vector op=<0,0,step>;
integer foo=1;
default
{
state_entry()
{
llSetColor(col,ALL_SIDES);
llSetTimerEvent(delay);
}
timer()
{
col += op;
llSetColor(col,ALL_SIDES);
if(col.x>=1|col.y>=1|col.z>=1)
{
foo++;
if(foo==8) foo=1;
op.x=(foo&1)*step;
op.y=((foo&2)>>1)*step;
op.z=((foo&4)>>2)*step;
col=<0,0,0>;
}
}
}


Its a quick hack, seems like there must be more colors....
Try to figure out how it works :P
feel free to change the 'delay' and 'step' values
Markubis Brentano
Hi...YAH!!
Join date: 15 Apr 2006
Posts: 836
07-14-2006 15:07
From: Ohforf Uram
I guess the last loop runs forever
CODE

else while (color.x == 1.0 & color.y == 1.0 & color.z >= .0)
{
color.z += .01;
llSetColor(color,ALL_SIDES);
}



Right, that last loop makes it stay at yellow. I've since fixed that to keep loping back thorugh the colors. But for some reason after a certain amount of loops , it just stops changing.


I'll try yours later tonight.

thanks :-)