POV-Ray : Newsgroups : povray.newusers : RGB<->HEX : Re: RGB<->HEX Server Time
30 Jul 2024 06:27:00 EDT (-0400)
  Re: RGB<->HEX  
From: Slime
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

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