Sunday, January 3, 2010

Second Life Scripting Colour Code Explained

Kia ora tātou – Hello EveryoneOpens a new window in Koru
I thought I’d start the year off with a colourful post. I’ve been doing some building in Second Life (SL) recently. I got stuck when I came to interpreting how the colour codes work when scripting some effects.

Perhaps I should explain for those who are not so familiar with SL.

All of SL, including the avatars that frequent it, is constructed from what are known as prims, or ‘primitives’ – polygonal three-dimensional shaped objects, like the ones Kallan demonstrates here.

Of course, not all that can be seen in SL is made entirely from these primitive shapes alone. They can be distorted by an effect, called sculpting, to reshape, or ‘tortured’ by changing their shape and size by other means.

Painting things in SL

Opens a new window in Koru
Colouring, or painting prims can be done in at least two ways. Choosing a single colour by using the colour picker, is a way of painting. The S-shaped sculpted sphere, above, was coloured this way.

Lara Nguya
Another is selecting a texture, which is really an uploaded image, and using this to give a defined pattern or intricate detail to the prim.

The picture here shows my friend Lara Nguya wearing a pendant that is decorated and coloured using this texturing method.


The standard RGB colour code is used. Each colour is defined digitally (8-bit) by its Red, Green and Blue components – shown as numbers between 255 and 0, in so-called vector arrays.


Colour Picker

The code for white is (255, 255, 255) and for black is (0, 0, 0). All other available colour combinations in the colour picker occur as permutations between these two vectors.

Scripts

Opens a new window in KoruOne way of imparting effects to objects in SL is by using scripts. In Lara’s candle, for instance, she uses a script that gives the wick the effect of a flickering flame.

When it came to scripting, I was completely baffled at first by colour codes and how they worked. Lara, showed me that an arithmetical code is used in scripting – different from the 8-bit coding used for colours in non-scripted prims.

The arithmetical code embraces a similar RGB range of colours, with some minor limitation in the range of hues available.
The RGB components are represented by numbers between 1 and 0, instead of 8-bit digital numbers between 255 and 0.

An easy conversion

Lara explained it to me this way:

Whereas 255 is the maximum number allowable in the 8-bit digital code, the corresponding maximum number is 1.0 for scripts and for some other uses in SL.

This means that any RGB code has to be converted to the equivalent code before it can be used in a script.
The numbers in the 8-bit digital codes must be divided by 255 to be corrected for use in scripting.

The code for white used in script becomes < 1, 1, 1 > and the script code for black becomes < 0, 0, 0 >.

sapgreen(48, 128, 20)

The arithmetic in the code conversion for sapgreen is as follows:

    48 converts to 48/255 = .19

    128 converts to 128/255 = .50

    20 converts to 20/255 = .08

So sapgreen 8-bit digital code (48, 128, 20) becomes < .19, .50, .08 > .

Another example is blueviolet. Its 8-bit digital code is (138, 43, 226). The code for the colour used in script is < .51, .17, .89 >.

The same process can be used for any other colour expressed in 8-bit digital code.

I am grateful for assistance and advice given to me by Lara Nguya.


Ka kite anō – Catch ya later

2 comments:

blu8bird said...

Very informative, well written instructions. Thanks Kallen! This is me and my work...

http://news.nationalgeographic.com/news/2008/09/photogalleries/2008-best-science-photos/photo8.html


Roselle Bolissima

Blogger In Middle-earth said...

Kia ora e Roselle!

Thanks for the encouragement! I appreciate that, coming from a scripter in SL. Thanks also for the link! Loved the Mad Hatter's Tea - well done!

Good that you had time to drop by.

Catchya later