Jump to content

Hexcode to Vector function


Rowen Stipe
 Share

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

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

Recommended Posts

This function takes in a hex color code and concerts it into an RGB vector for LSL color. There is a basic check for if there's a # randomly in the string but no validation of the hexcode.

//Convertes a hexcode into vector
vector hex2Vec(string hex)
{
    //remove poud sign from hexcode
    if(llSubStringIndex(hex, "#") == 0)
    {
        hex = llDeleteSubString(hex, 0, 0);
    }
    //sainty check to make sure there's no pound sign
    else if (llSubStringIndex(hex, "#") > 0)
    {
        llOwnerSay("Invalid hexcode: "+hex);
        return ZERO_VECTOR;
    }
    float r = (float)("0x"+llGetSubString(hex, 0, 1))/255;
    float g = (float)("0x"+llGetSubString(hex, 2, 3))/255;
    float b = (float)("0x"+llGetSubString(hex, 4, 5))/255;

    return <r,g,b>;
}

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 758 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...