Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

LSL Related JavaScript Question

Patrick2 Chama
Registered User
Join date: 15 Sep 2006
Posts: 52
03-17-2007 11:50
Anyone have a simple JavaScript function that would take a hex color value and convert it to an LSL vector?
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
03-18-2007 05:34
Well, here's what it might look like in LSL:

CODE

vector Col2Vect( string Color )
{
return < (float)( "0x" + llGetSubString( Color, 0, 1 ) ) / 255.,
(float)( "0x" + llGetSubString( Color, 2, 3 ) ) / 255.,
(float)( "0x" + llGetSubString( Color, 4, 5 ) ) / 255. >;
}
I don't know the Java equivalent of llGetSubString, or if it will directly cast a string beginning with "0x" to a numeric type of value equal to the string's hex value, as LSL does.
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
03-18-2007 10:44
CODE

function Col2Vect( Color )
{
var red = Color.substring(0,2);
var green = Color.substring(2,4);
var blue = Color.substring(4,6);
return "<" + parseInt("0x" + red) / 255.0 + ", "
+ parseInt("0x" + green) / 255.0 + ", "
+ parseInt("0x" + blue) / 255.0 + ">";
}


Something like that I expect. not tested it but the 'parseInt("0x" +' works for converting from Hexadecimal bytes to integers.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Patrick2 Chama
Registered User
Join date: 15 Sep 2006
Posts: 52
03-18-2007 19:16
From: nand Nerd
CODE

function Col2Vect( Color )
{
var red = Color.substring(0,2);
var green = Color.substring(2,4);
var blue = Color.substring(4,6);
return "<" + parseInt("0x" + red) / 255.0 + ", "
+ parseInt("0x" + green) / 255.0 + ", "
+ parseInt("0x" + blue) / 255.0 + ">";
}


Something like that I expect. not tested it but the 'parseInt("0x" +' works for converting from Hexadecimal bytes to integers.


Thanks to both of you. This worked great! I never did have a talent for JavaScript :)