Color and Scripting
Help Portal: |
Avatar | Bug Fixes | Communication | Community | Glossary | Land & Sim | Multimedia | Navigation | Object | Video Tutorials | Viewer | Wiki | Misc |
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Using color in LSL scripting is fairly easy. If works by combining values of red, green, and blue light. They are stored like this:
float red_value;
float green_value;
float blue_value;
vector color = <red_value, green_value, blue_value>;
// or:
// color.x = red_value;
// color.y = green_value;
// color.z = blue_value;
Each red, green, or blue value can be between 0.0 (no color saturation) to 1.0 (total color saturation). These values are determined by combining the colors as if they were light, not paint. Therefore, the combination of all three in total saturation is white. The combination of all three with no saturation is pitch black. If there is not saturation on two values, and the third is saturated, you get a pure color.
Color | Hexadecimal code | LSL color representations |
---|---|---|
NAVY | #001f3f | <0.000, 0.122, 0.247>
|
BLUE | #0074d9 | <0.000, 0.455, 0.851>
|
AQUA | #7fdbff | <0.498, 0.859, 1.000>
|
TEAL | #39cccc | <0.224, 0.800, 0.800>
|
OLIVE | #3d9970 | <0.239, 0.600, 0.439>
|
GREEN | #2ecc40 | <0.180, 0.800, 0.251>
|
LIME | #01ff70 | <0.004, 1.000, 0.439>
|
YELLOW | #ffdc00 | <1.000, 0.863, 0.000>
|
ORANGE | #ff851b | <1.000, 0.522, 0.106>
|
RED | #ff4136 | <1.000, 0.255, 0.212>
|
MAROON | #85144b | <0.522, 0.078, 0.294>
|
FUCHSIA | #f012be | <0.941, 0.071, 0.745>
|
PURPLE | #b10dc9 | <0.694, 0.051, 0.788>
|
WHITE | #ffffff | <1.000, 1.000, 1.000>
|
SILVER | #dddddd | <0.867, 0.867, 0.867>
|
GRAY | #aaaaaa | <0.667, 0.667, 0.667>
|
BLACK | #111111 | <0.067, 0.067, 0.067>
|
Converting Hexadecimal to Vectors
To convert from a hexadecimal values used in CSS or HTML to ones usable in Second Life scripting, first convert the number for the red, green and blue saturation from hexadecimal to decimal, then divide that number by 255. Do bear in mind that 3-digit codes are a shorthand form, so each digit should be doubled (F becomes FF, 4 becomes 44, 0 becomes 00 etc)
Form\Channels | Red | Green | Blue |
---|---|---|---|
Hexadecimal | FF | CC | 00 |
Decimal | 255 | 204 | 0 |
Saturation Float | 1.0 | 0.8 | 0.0 |
total saturation:
- hexadecimal: FF
- decimal: 255
- float: 1.0
no saturation:
- hexadecimal: 00
- decimal: 0
- float: 0.0
Therefore:
#F0F = #FF00FF = <1.0,0.0,1.0>