|
|
On 12/15/2016 4:51 PM, Mike Horvath wrote:
> I have a JavaScript expression:
>
> "0123456789ABCDEF".charAt((n-n%16)/16) + "0123456789ABCDEF".charAt(n%16)
>
> It is used to convert an integer between 0 and 255 to hexadecimal code.
>
> How do I rewrite this in POV-Ray? Thanks.
>
> Mike
Never mind. I forgot I can use arrays instead of strings. Here is some
code to do it:
#macro CRGB2HEX(Color)
#local RGBFT = color Color;
#local R = RGBFT.red;
#local G = RGBFT.green;
#local B = RGBFT.blue;
concat(CDEC2HEX(R), CDEC2HEX(G), CDEC2HEX(B))
#end
#macro CDEC2HEX(n)
#local HexArray = array[16]
{"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}
#local n = max(0, min(255, round(n * 255, 0)));
#local Num1 = (n - mod(n, 16))/16;
#local Num2 = mod(n, 16);
concat(HexArray[Num1], HexArray[Num2])
#end
Mike
Post a reply to this message
|
|