Jump to content

Colours and Darkening


Wandering Soulstar
 Share

You are about to reply to a thread that has been inactive for 1815 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi All,

Have a question in regards to setting colours, and its not about the code/functions .. those I know, but rather about getting the colour vector that I want. I am currently building a house for a client, and one of the things I want to put into it is the capability for them to change the colours of the walls, and in fact define the colours they want available. Now the basics are simple, but where I am running up blank in in the fact that the walls include an recessed base board, and for effect this needs to be a few shades darker than the colour of the wall itself ... and that is what I cannot figure out. Looking at the colour changer in world, set a colour and then move the slider at the right. The changes in the LSL values follow no logic that I could calculate as, other than going down when it gets darker, which ones move, and by how much is impossible for me to tell. Looking at the Hue Sat and Lum values can see that the move is only in the L value .. so my question then lies .. is there a way to convert an LS Colour vector to HSL and then back again?

Thanks!!!

Link to comment
Share on other sites

I just literally translated the actual Wikipedia article into LSL. (For fun, of course. Sadly this wasn't a very educational exercise even for me.)

vector rgb2hsl(vector color)
{
    float H; float S; float L;

    float min = llListStatistics(LIST_STAT_MIN, [color.x, color.y, color.z]);
    float max = llListStatistics(LIST_STAT_MAX, [color.x, color.y, color.z]);

    if(max == min)          H = 0;
    else if(max == color.x) H = 60 * (0 + ((color.y - color.z) / (max - min)));
    else if(max == color.y) H = 60 * (2 + ((color.z - color.x) / (max - min)));
    else if(max == color.z) H = 60 * (4 + ((color.x - color.y) / (max - min)));
    if(H < 0) H += 360;

    if(max == 0) S = 0;
    else         S = (max - min) / (1 - llFabs(max + min - 1));

    L = (max + min) / 2;

    return <llRound(H), llRound(S*100), llRound(L*100)>;
}

default
{
    state_entry()
    {
        llOwnerSay( (string)rgb2hsl(llGetColor(0) );
    }
}

I have deliberately left out some very obvious optimizations.

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1815 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...