Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Truly Random Hue

Abu Nasu
Code Monkey
Join date: 17 Jun 2006
Posts: 476
11-23-2006 01:14
I've spent the last few years writing my own plug-ins for Photoshop using Filter Meister. I have a rather strong background when it comes to manipulating various colour spaces. Imagine my surprise when I found out that SL and LSL are lacking when it comes to colour manipulation. The horror!

Been working on a rather bland project and needed to add some colour. The random colour scripts out there are seriously lacking for the blandness of my project. I need random colour and I mean *serious* colour. The generic random colour generators out there can generate pastels, darks, brights, and shades of grey. Those do me no good. What I need is random hue with tons of saturation. Since everything else out there seems to be lacking, seems like a good time to dip into my colour space manipulation background to learn more about LSL. After all, nothing says scripting like actually scripting.

I now have my very first script. It feels good.

It's based on the Hue <> RGB paradigm. Because of the ranges used in various places in LSL, takes advantage of bits. I don't know if it's elegant, but I think it's clever for my first script.

For a lot of uses, this is probably over-kill and probably won't be noticed. But it suits my purposes perfectly.

And it still feels good.
Cheers to learning LSL.


// Truly Random Hue by Abu Nasu

// master list for random ranges
list numbs=[7,13,19,28,49,52];

// random function for floats
// from the wiki
float randBetween(float min, float max)
return llFrand(max - min) + min;

// random function for integers
// from the wiki
integer RandInt(integer lower, integer higher)
integer Range = higher - lower;
integer Result = llFloor(llFrand(Range + 1)) + lower;
return Result;


touch_start(integer total_number)
// declares for this level
integer rhigh;
integer rlow;
integer ghigh;
integer glow;
integer bhigh;
integer blow;
integer rando;
integer bitMe;
float newr;
float newg;
float newb;

// get random number from master list

// bitwise jig to get ranges for random colour function
rhigh=bitMe & 1;
rlow=(bitMe & 2 ) >> 1;
ghigh=(bitMe & 4 ) >> 2;
glow=(bitMe & 8 ) >> 3;
bhigh=(bitMe & 16 ) >> 4;
blow=(bitMe & 32 ) >> 5;

// get the random colours using ranges
newr = randBetween(rlow,rhigh);
newg = randBetween(glow,ghigh);
newb = randBetween(blow,bhigh);

// set the new colour
llSetColor(<newr,newg,newb>, ALL_SIDES);

} // end touch_start

} // end default
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
11-23-2006 09:55
i've got nothing. ;)