Jump to content
Wandering Soulstar

Colours and Darkening

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!!!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...