POV-Ray : Newsgroups : povray.newusers : RGB<->HEX : Re: RGB<->HEX Server Time
2 Nov 2024 03:14:51 EDT (-0400)
  Re: RGB<->HEX  
From: Kurts
Date: 10 Sep 2004 13:06:19
Message: <kurtzlepirate-085462.19061810092004@news.povray.org>
In article <web.4141045b864bcff549700cac0@news.povray.org>,
 "Mike Thorn" <films!@!roboticsresources.com> wrote:

> Hi,
> 
> Is there a simple way to convert a hex value into Pov's RGB system?
> 
> I'm not sure what exactly to call Pov's vector system so I had difficulty
> researching this myself. If anyone can help me, I would appreciate it. I'm
> sure somebody out there is able. :)
> 
> Thanks,
> ~Mike
> 
> 

hi,

try this :
//  --- the macro -------------------------------------------------------------
#macro hex2rgb (hexString)
  #macro hex2dec (theHexValue)
    (asc(theHexValue)>64?asc(theHexValue)-55:asc(theHexValue)-48)
  #end
  
  <16*hex2dec(substr(hexString,1,1))+hex2dec(substr(hexString,2,1)),
  16*hex2dec(substr(hexString,3,1))+hex2dec(substr(hexString,4,1)),
  16*hex2dec(substr(hexString,5,1))+hex2dec(substr(hexString,6,1))>/255
#end

//  --- sample ----------------------------------------------------------------
#declare HexColor = "36F0CF";
#declare PovColor = hex2rgb(HexColor);

#debug concat("\n Red = ",str(PovColor.red,7,6)," Green = 
",str(PovColor.green,7,6)," Blue = ",str(PovColor.blue,7,6),"\n")


Post a reply to this message

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