POV-Ray : Newsgroups : povray.newusers : RGB<->HEX Server Time
4 Nov 2024 23:19:15 EST (-0500)
  RGB<->HEX (Message 1 to 5 of 5)  
From: Mike Thorn
Subject: RGB<->HEX
Date: 9 Sep 2004 21:35:00
Message: <web.4141045b864bcff549700cac0@news.povray.org>
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


Post a reply to this message

From: Slime
Subject: Re: RGB<->HEX
Date: 9 Sep 2004 22:17:22
Message: <41410eb2$1@news.povray.org>
> Is there a simple way to convert a hex value into Pov's RGB system?


First, convert the hex value into three numbers from 0 to 255 by splitting
it up into 3 sets of 2 digits and interpreting each pair of digits as a
single number.

To do this, take the first of the two digits, translate it to a decimal
number (0=0, 1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9, A=10, B=11, C=12,
D=13, E=14, F=15) and multiply it by 16. Then take the second digit and
translate it the same way, and add that to the first part. This should give
you a number from 0 to 255.

Then take those three numbers and put them in a vector and scale the vector
by 1/255.

So for example, with the color #36F0CF :

36 -> 3*16 + 6  = 54
F0 -> 15*16 + 0 = 240
CF -> 12*16 + 15 = 207

color: rgb <54, 240, 207>/255

It would probably be possible to make a macro that automates this process.
One may already exist.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Mike Thorn
Subject: Re: RGB<->HEX
Date: 9 Sep 2004 23:10:00
Message: <web.41411a7c338914b349700cac0@news.povray.org>
"Slime" <fak### [at] emailaddress> wrote:
> So for example, with the color #36F0CF :
>
> 36 -> 3*16 + 6  = 54
> F0 -> 15*16 + 0 = 240
> CF -> 12*16 + 15 = 207
>
> color: rgb <54, 240, 207>/255
>
> It would probably be possible to make a macro that automates this process.
> One may already exist.

Wonderful; that's a huge help. Thanks a bunch!

Actually it's partially automated for me - GIMP, my main image manipulation
piece, automatically gives a hex value for RGB and vice versa, so I just
need to do the /255 part.

Thanks again,
~Mike (desperately hoping this reply doesn't register as a new topic)


Post a reply to this message

From: Kurts
Subject: Re: RGB<->HEX
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

From: sprocket
Subject: Re: RGB<->HEX
Date: 10 Sep 2004 14:20:01
Message: <web.4141efa6338914b321ba3a7e0@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 mike,
heres a color picker around 300kb and can pick  values from  anywhere on
screen
displays rgb and hex at same time. and stays on top so you can see it easy.
http://www.datastic.com/tools/colorcop/
heaps features include selectable zoom etc.

sprocket aka mongke :)


Post a reply to this message

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