|
![](/i/fill.gif) |
Mike Williams <nos### [at] econym demon co uk> wrote:
> #local C=0;
> #while (strlen(H)>0)
> #local A=substr(H,1,1);
> #local H=substr(H,2,strlen(H)-1);
> #if (strcmp(A,"0")=0) #local C=C*16; #end
> #if (strcmp(A,"1")=0) #local C=C*16+1; #end
> #if (strcmp(A,"2")=0) #local C=C*16+2; #end
> #if (strcmp(A,"3")=0) #local C=C*16+3; #end
> #if (strcmp(A,"4")=0) #local C=C*16+4; #end
> #if (strcmp(A,"5")=0) #local C=C*16+5; #end
> #if (strcmp(A,"6")=0) #local C=C*16+6; #end
> #if (strcmp(A,"7")=0) #local C=C*16+7; #end
> #if (strcmp(A,"8")=0) #local C=C*16+8; #end
> #if (strcmp(A,"9")=0) #local C=C*16+9; #end
> #if (strcmp(A,"A")=0 | strcmp(A,"a")=0) #local C=C*16+10; #end
> #if (strcmp(A,"B")=0 | strcmp(A,"b")=0) #local C=C*16+11; #end
> #if (strcmp(A,"C")=0 | strcmp(A,"c")=0) #local C=C*16+12; #end
> #if (strcmp(A,"D")=0 | strcmp(A,"d")=0) #local C=C*16+13; #end
> #if (strcmp(A,"E")=0 | strcmp(A,"e")=0) #local C=C*16+14; #end
> #if (strcmp(A,"F")=0 | strcmp(A,"f")=0) #local C=C*16+15; #end
> #end
> #local R=int(C/256/256);
> #local G=mod(int(C/256),256);
> #local B=mod(C,256);
> rgb <R,G,B>/255
> #end
Code repetition is one of the biggest sins in programming.
How about this (it has the advantage to support both uppercase and
lowercase hexadecimal numbers, ie. "c2Ab0F" is ok):
#macro HTMLRGB(H)
#local value = 0;
#local len = strlen(H);
#local index = 1;
#while(index <= len)
#local char = asc(substr(H, index, 1)) - 48;
#if(char > 9) #local char = char - 7; #end
#if(char > 15) #local char = char - 32; #end
#local value = value*16 + char;
#local index = index + 1;
#end
<int(value/65536), mod(int(value/256), 256), mod(value,256)>
#end
--
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}// - Warp -
Post a reply to this message
|
![](/i/fill.gif) |