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

From Second Life Wiki
Jump to navigation Jump to search
(Brief explanation about how to get the right LSL values for a color - It still can be improved)
 
 
(3 intermediate revisions by the same user not shown)
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.


Once you have the values for R, G and B, you need transforming them for LSL, which expects the color as a vector, <R,G,B>, but values for R, G and B need to be from 0 to 1. So, if you have values from 0 to 255, for converting them into 0 to 1, you need dividing them by 255.
To mention a few examples:


This is, we have <R, G, B>, being R, G and B from 0 to 255, as usual, so LSL needs that you do this:
    <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


<R/255.0, G/255.0, B/255.0>
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 a 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.
for the definitive values for the color.


In order to find the RGB components of a color, there are a lot of resources in the web. Both this: http://www.allprofitallfree.com/color-wheel2.html and this: http://www.ficml.org/jemimap/style/color/wheel.html are good resources for it.
<b>NOTE:</b>
 
    <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:
 
* http://www.allprofitallfree.com/color-wheel2.html
* http://www.ficml.org/jemimap/style/color/wheel.html
 
<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:


As an example, if we want to use this blue tone:
    <6.0, 172.0, 255.0>/255.0


<6, 172, 255>
which means that the value we'll use for the color will be:


it needs to be converted performing this calculation:
    <0.023529, 0.67451, 1.0>


<6/255, 172/255, 255/255>
(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.)


which means that the value we'll put for the color will be this:
The colors mentioned above will also be written this way:


<0.023529, 0.67451, 1.0>
    <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

Latest revision as of 11:07, 12 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.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 a 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.

NOTE:

   <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