Tuesday, February 11, 2014

Tool: Color HUD

:: Get the codes for your scripts instantly - Select and click ::

Color HUD at Marketplace
By Auryn Beorn (2012)



The purpose of the "[Black Tulip] Color HUD (wear/top-left)" tool is to allow you to obtain quickly in your local chat (owner say - so you are not spamming anybody else around) the code of a color of your choice, for it to be written into a LSL script.


Wear the object "[Black Tulip] Color HUD (wear/top-left)". Once you wear it, the following shows up in your HUD:
Select the tone by clicking in the color palette. Then select the saturation by clicking the white to black bar. Click the "Say in chat" button, and there you have it: the color you want, written as the script expects it.

You only need to copy this code and paste it in your script, where it's required to be copied.


In case you're interested in knowing how to proceed in general (not with this tool) to get the value of any color, the following explains all what you need to know about how to write color codes in your LSL scripts.

This information is not required to simply use the HUD.

From my wiki page: http://wiki.secondlife.com/wiki/User:Auryn_Beorn/How_to_get_a_valid_LSL_color

Any color is always a combination of Red, Green and Blue values. Usually, these values go from 0 to 255. The higher the value, the more you have of that component. They're usually written it this order: R, G, B.

To mention a few examples:

<255, 0, 0>         RED
<255, 255, 0>       YELLOW (= RED + GREEN)
<128, 128, 128>     GRAY 50%
<0, 128, 0>         GREEN 50%
<0, 0, 0>           BLACK
<255, 255, 255>     WHITE

But scripts in SL need this written in a very specific way. We need to convert this. Scripts expect the numbers in a different range, so instead of writing, an example, the color red like this:

<255, 0, 0>

the three numbers have to be within the range from 0 to 1, so the color red would be written as follows:

<1.0, 0.0, 0.0>

What do we do, then, when we have a RGB code for a color we like, to "translate it" to LSL (the scripting language)?

We have to take the RGB, like here: 255, 255, 0
Put the three numbers between < and > and separate by commas, adding the decimal point:

<255.0, 255.0, 0.0>

and then we have to divide the three numbers by 255.0, so we get:

<255.0/255.0, 255.0/255.0, 0.0/255.0>

which gives as result:

<1.0, 1.0, 0.0>

So, in general, once we have the values for R, G and B, we need to "translate" them to LSL, which expects the color as a vector, <R, G, B>, but values for R, G and B have to be from 0 to 1. So, if we have values from 0 to 255, to convert them into 0 to 1, we need to divide them by 255.

This is, we have <R, G, B>, being R, G and B from 0 to 255, as usual, so LSL needs that we perform the following operation:

<R/255.0, G/255.0, B/255.0>

for the definitive values for the color.


<R/255.0, G/255.0, B/255.0>

is basically the same as:

<R, G, B>/255.0

being the last one, preferred if you typed like that in a script.

There are a lot of resources in the web to find the RGB components of a color. The two following links are good resources for this:

EXAMPLE: Let's suppose we have the blue tone <6, 172, 255>, as it will be written with the standard 0-255 range for RGB.

To convert this <6, 172, 255> to a valid color for LSL, we have to perform the following calculation:

<6.0, 172.0, 255.0>/255.0

which means that the value we'll use for the color will be:

<0.023529, 0.67451, 1.0>

(Yes, we could leave it as <6.0, 172.0, 255.0>/255.0, but it's better if we save the script to do unnecessary calculations.)

The colors mentioned above will also be written this way:

<1.0, 0.0, 0.0>         RED
<1.0, 1.0, 0.0>         YELLOW (= RED + GREEN)
<0.5, 0.5, 0.5>         GRAY 50%
<0.0, 0.5, 0.0>         GREEN 50%
<0.0, 0.0, 0.0>         BLACK
<1.0, 1.0, 1.0>         WHITE