Difference between revisions of "User:Auryn Beorn/How to get a valid LSL color"

From Second Life Wiki
Jump to navigation Jump to search
Line 1: Line 1:
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.
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:
To mention a few examples:


<255, 0, 0>                 RED
    <255, 0, 0>         RED
<255, 255, 0>           YELLOW (= RED + GREEN)
    <255, 255, 0>       YELLOW (= RED + GREEN)
<128, 128, 128>    GRAY 50%
    <128, 128, 128>    GRAY 50%
<0, 128, 0>             GREEN 50%
    <0, 128, 0>         GREEN 50%
<0, 0, 0>                   BLACK
    <0, 0, 0>           BLACK
<255, 255, 255>    WHITE
    <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:
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>
    <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:
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>
    <1, 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)?
What do we do, then, when we have a RGB code for a color we like, to "translate it" to LSL (the scripting language)?
Line 24: Line 23:
Put the three numbers between < and > and separate by commas:
Put the three numbers between < and > and separate by commas:


<255, 255, 0>
    <255, 255, 0>


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


<255/255, 255/255, 0/255>
    <255/255, 255/255, 0/255>


  which gives as result:
which gives as result:


<1.0, 1.0, 0.0>
    <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.
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.
Line 38: Line 37:
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:
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>
    <R/255.0, G/255.0, B/255.0>


for the definitive values for the color.
for the definitive values for the color.
Line 45: Line 44:
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:
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:


http://www.allprofitallfree.com/color-wheel2.html
* http://www.allprofitallfree.com/color-wheel2.html
http://www.ficml.org/jemimap/style/color/wheel.html
* http://www.ficml.org/jemimap/style/color/wheel.html


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.
<b>EXAMPLE:</b> 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:
To convert this <6, 172, 255> to a valid color for LSL, we have to perform the following calculation:


<6/255, 172/255, 255/255>
    <6/255, 172/255, 255/255>


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


<0.023529, 0.67451, 1.0>
    <0.023529, 0.67451, 1.0>


(Yes, we could leave it as <6/255, 172/255, 255/255>, but it's better if we save the script to do unnecessary calculations.)
(Yes, we could leave it as <6/255, 172/255, 255/255>, but it's better if we save the script to do unnecessary calculations.)
Line 62: Line 61:
The colors mentioned above will also be written this way:
The colors mentioned above will also be written this way:


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

Revision as of 00:19, 2 February 2012

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>

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:

   <255, 255, 0>

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

   <255/255, 255/255, 0/255>

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.


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/255, 172/255, 255/255>

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/255, 172/255, 255/255>, 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