Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Hex to bin. Or Web colors to LSL colors.

LordJason Kiesler
imperfection inventor.
Join date: 30 May 2004
Posts: 215
12-12-2004 04:52
I havnt been able to find any good lists of colors in sl for the LSL vector format. " <1,0,0.5> ".

So i looked around the web for lists of colors with there names and values and mostly found hex colors..

So what to do? make a script that converts hex to dec, and then makes a <255,255,255> color a <1.0,1.0,1.0> vector :-)

The script the way it is just listens to its owner for something like, "Cyan 00FFFF", and then seperates the name and converts the hex to lsl color, and adds them both to a list to use however.



CODE
list colors;

// For getting the % of 255 and making a LSL vector for the color.
vector llColor(vector C){
return <C.x / 255, C.y / 255, C.z / 255>;
}

// make a hex a dec.
integer hex2Dec(string hex){
integer i;
integer final = 0;
list chars;
// first make a list of every char it got in, "string hex"
for(i = 0; i < llStringLength(hex) + 1; i++){
chars += llGetSubString(hex,i - 1,i - 1);
}
float calc = (llGetListLength(chars) - (llGetListLength(chars) * 2));
// go through each char and find its value according to its place in the base 16 then add it to final.
for( i = -1; i > calc; i--){
integer temp;
temp = llList2Integer(chars,i);

if(llToLower(llList2String(chars,i)) == "a"){temp = 10;}
if(llToLower(llList2String(chars,i)) == "b"){temp = 11;}
if(llToLower(llList2String(chars,i)) == "c"){temp = 12;}
if(llToLower(llList2String(chars,i)) == "d"){temp = 13;}
if(llToLower(llList2String(chars,i)) == "e"){temp = 14;}
if(llToLower(llList2String(chars,i)) == "f"){temp = 15;}

final += (integer)(temp * llPow(16, (llAbs(i) - 1)));
}
return final;
}

default{
state_entry(){
llListen(0, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message){
list words = llParseString2List(message, [" "], []);
vector Lcolor = llColor(<hex2Dec(llGetSubString(llList2String(words, 1), 0, 1)), hex2Dec(llGetSubString(llList2String(words, 1), 2, 3)), hex2Dec(llGetSubString(llList2String(words, 1), 4, 5))>);
colors += llList2String(words,0);
colors += Lcolor;
llSetColor(Lcolor, ALL_SIDES);
llWhisper(0, llList2String(words,0) + " " + (string)Lcolor);
}
}


I know its probably not the BEST way, but ide be interested in any comments on how to do this better.
_____________________
"no, my alt is clean on crashing any sims"
Bird Raven
CrashBoomworks
Join date: 13 Dec 2004
Posts: 27
And
12-30-2004 10:19
And this will remain to be the solid reason why his name isn't Jason.. its LORD
CODE
<marquee>LORDJASON !!!!!!!!!!!!!</marquee>


All the programmers will imagine that to be moving ... 0_o
Apricot Winx
Registered User
Join date: 25 Jan 2007
Posts: 0
02-04-2007 00:52
this is AWESOME !

works perfectly.