|
![](/i/fill.gif) |
Ken wrote:
> Any chance of doing a hex2rgb script ?
Well, thats something I do know how to do! Gotta love them macros.
(BTW: Thanks for signing my guestbook!)
// Persistence of Vision Ray Tracer Scene Description File
// File: hex2rgb.pov
// Vers: 3.1
// Desc: Convert HTML style hex colors into POV RGB vectors
// Date: Wednesday, October 14, 1998
// Auth: Theran Cochran
#macro Hex2Int(hex)
#local curStr = strlwr(hex)
#local zeroChar = asc("0");
#local nineChar = asc("9");
#local aChar = asc("a");
#local fChar = asc("f");
#local fin = false;
#local value = 0;
#local temp = 0;
#local isNum = false;
#while(!fin)
#local curChar = asc(curStr);
#if((curChar >= zeroChar) & (curChar <= nineChar))
#local isNum = true;
#local temp = curChar - zeroChar;
#local value = value*16 + temp;
#else
#if((curChar >= aChar) & (curChar <= fChar))
#local isNum = true;
#local temp = 10 + curChar - aChar;
#local value = value*16 + temp;
#else
#local fin = true;
#end
#end
#if(strlen(curStr))
#local curStr = substr(curStr, 2, strlen(curStr) -1)
#else
#local fin = true;
#end
#end
#if(!isNum) #local value= -1; #end
value
#end
#macro IndexOf2(string, sstring, i)
#local stringlen = strlen(string);
#local sstringlen = strlen(sstring);
#local fin = false;
#local index = i;
#if(stringlen < sstringlen)
#local index = -1;
#local fin = true;
#end
#if(sstringlen <= 0)
#local index = -1;
#local fin = true;
#end
#while(!fin)
#if(index > stringlen - sstringlen)
#local index = -1
#local fin = true;
#end
#if(strcmp(substr(string, index + 1, sstringlen), sstring) = 0)
#local fin = true;
#end
#local index = index + 1;
#end
index - 1
#end
#macro IndexOf(string, sstring)
IndexOf2(string, sstring, 0)
#end
#macro Hex2RGB(string)
#local warn = false;
#if(strlen(string) < 7)
#local warn = true;
#else
#local redval = Hex2Int(substr(string, 2, 2))
#if(redval < 0) #local warn = true; #end
#local greenval = Hex2Int(substr(string, 4, 2))
#if(greenval < 0) #local warn = true; #end
#local blueval = Hex2Int(substr(string, 6, 2))
#if(blueval < 0) #local warn = true; #end
#end
#if(warn)
#warning concat("\nWARNING: Hex2RGB #macro: Bad hex value: \"", string, "\"\n")
#end
<redval/255, greenval/255, blueval/255>
#end
//Begin test scene
#declare camera_location = <1, 3, -5>;
#declare camera_look_at = <0, 0, 0>;
#declare camera_angle = 45;
camera {
location camera_location
look_at camera_look_at
angle camera_angle
}
light_source { 0, color rgb <1, 1, 1>*1.25
// area_light x*50, z*50, 3, 3
adaptive 0
jitter
translate y*1000
rotate <-30, -45, 0>
}
sphere { 0, 1 pigment { color Hex2RGB("#4321af") } }
//<---- End of hexrgb.pov
--
Theran Cochran - shi### [at] foto infi net
http://members.xoom.com/theran/
Post a reply to this message
|
![](/i/fill.gif) |