POV-Ray : Newsgroups : povray.newusers : Colour conversion - HTML to RGB : Re: Colour conversion - HTML to RGB Server Time
30 Jul 2024 02:29:17 EDT (-0400)
  Re: Colour conversion - HTML to RGB  
From: Mike Williams
Date: 1 Nov 2004 13:01:08
Message: <JZmaKAAflnhBFwnw@econym.demon.co.uk>
Wasn't it David Robinson who wrote:
>I've done a bit of digging around and I can't seem to come up with anything.
>
>What I'm trying to do is use HTML colours instead of RGB values. This is
>really for ease of programming, to save me having to split and recalculate
>the HTML values into RGB. I don't mind doing it, but is there an option to
>supply POV with HTML values? Or will it need a conversion script somewhere?

If you mean HTML codes like "FF0088", then it's possible to write a
macro. It's not particularly pretty because you've got to perform
arithmetic on the contents of strings.

#macro HTMLRGB(H)
 #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                        


Use it like 

    pigment {HTMLRGB("FF0088")}


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.