Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script: Random Color Generator

Peter Linden
Registered User
Join date: 18 Nov 2002
Posts: 177
04-15-2003 09:21
Script: Flashing Random Colors

A random color generator.

Summary: The following script will make an object that, once attached, will change to a random color every random number of seconds.

Usage: you can change the number of seconds that it fluxuates between by changing both the base_delay and the variable_delay. The base_delay is the minimum amount of time that will happen between color changes. Then a number between 0 and the value of variable_delay is added to the base to give you the random time between changes.

CODE

integer toggle = 1; // This is our toggle switch for turning the
// script on and off. You will never need to
// change its value.

float base_delay = 1.0; // This is the minimum amount of delay
// that will happen between color changes.
// If you want a consistently longer or
// shorter delay, change this value.

float variable_delay = 1.5; // This is the maximum delay added to
// the base_delay. If you want a wider
// variation in the delay, then increase
// the value. If you want less variance.
// then decrease it.

default
{
touch_start(integer counter)
{
toggle *= -1; // Here we multiply negative one, to change its
// sign.

if(toggle < 0) // We test to see if it is less than 0, and if it
// is, then we turn on the color changer.
{
llSetTimerEvent(llFrand(variable_delay) + base_delay);
}
else
{
llSetTimerEvent(0);
}
}

timer()
{
llSetColor(<llFrand(1),llFrand(1),llFrand(1)>,ALL_SIDES);
llSetTimerEvent(llFrand(variable_delay) + base_delay);
}
}


Credits:
Script written by:
Nada Epoch 11-25-02
Phil Metalhead
Game Foundry Leaɗer
Join date: 11 Mar 2003
Posts: 291
Discussion Thread
04-24-2003 16:26
/54/a3/44195/1.html
ne

i think this script is a BAD script. four llFrand() calls every time the timer runs. all it needs is for someone to set the timer to 1 second, and put a few objects around with that script, and you've got a recipe for a sim bomb, or at least something to degrade the performance of a sim needlessly, for something as superficial as a color changing item!
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
05-21-2003 17:38
ok so in answer to this i wrote a couple scripts that took one random number and split it into three random numbers, however... they just didn't look right, infact they all ended up down right predictable.

here is the relevant lines of code that i tried:
CODE


{
float random = llFrand(1);
llSetColor(<random/2 +1/2,1-random,random>,ALL_SIDES);
}

{
float random = llFrand(1);
llSetColor(<2*random/(1+random),1/(1+random),random>,ALL_SIDES);
}

....

there were two more i tried, but i cannot remember them... anyways, all i can think of doing is say grabbing the digits from the random number that the script generated, such that the 10ths and the 100ths place would be the first random number, and 1,000th and the 10,000th would be the second, and the 1,000,000th and 10,000,000th places would be the third... but well i didn't try it.

if you have a killer one that works, post it, cause i don't feel like writing the vector for the way i just described heh
_____________________
i've got nothing. ;)
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
05-21-2003 22:52
Only 1 llFrand? ok.... although its up to you to decide if this is better than 3 llfFrand() calls.

CODE
        float num = llFrand(1) * 256;
integer num1 = (integer)num;
num = (num - num1) * 256;
integer num2 = (integer)num;
num = (num - num2) * 256;
integer num3 = (integer)num;
vector color = <num1,num2,num3>;
color = color / 256;
llSetColor(color,ALL_SIDES);
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
05-22-2003 12:24
or
CODE

float random = llFrand(1);
float random2 = random*10.0-llFloor(random*10);
float random3 = random*100.0-llFloor(random*100);
llSetColor(<random ,random2 ,random3>,ALL_SIDES);
llSetText((string)llGetColor(-1),<1,1,1>,1);
llSetTimerEvent(random + base_delay);
_____________________
i've got nothing. ;)
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
05-26-2003 01:17
Why don't you just call fRand once every timer tick and only adjust one RGB portion instead of all three at once?

i.e.:

tick ---> Change red component
tick ---> Change green component
tick ---> Change blue component
tick ---> Change red component
etc. etc. etc.

By the way, is the random number generator really that expensive?
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
05-27-2003 00:44
Can anyone explain why llFrand is so taxing on the server?

Previously it was observed that the ravers' lighted color sticks had a major impact on server performance because of their calls to llFrand. Tcoz offered an alternative using llSetTextureAnim and a texture consisting of random color squares. Maybe that technique is what we should be recommending instead of this script.
Smokey Newman
Registered User
Join date: 12 Feb 2007
Posts: 6
06-15-2008 17:55
Is there anyway this can be doe with just three colours beibg picked at Random.