decimal to hex translation for colors



> Jorge Calvo <Jorge.Calvo <at> avemaria.edu> writes:
> 
>> Assuming that I have the rgb intensities as integers (or floats,
>> if that is easier), is there a way of turning these into hexadecimal
>> numbers?  Or better yet, is there a way to take a triple of
>> intensities and produce the corresponding #rrggbb string?
> 
> How about something like this:
> 
> (%i1) foo : printf (false, "#~2x~2x~2x", 127, 63, 31);
> (%o1)                               #7F3F1F
> (%i2) foo;
> (%o2)                               #7F3F1F
> 
> HTH
> 
> Robert Dodier
> 

Thanks, RD.  That almost did the trick, but gave me spaces (instead of a leading zero) when the input was less than 16.  So I did a little investigating and found that this finished the job:

(%i1) rgbcolor(r, g, b) := printf(false, "#~2,'0X~2,'0X~2,'0X", r, g, b) $

(%i2) rgbcolor(7, 35, 255);
(%02) #0723FF

Thanks again for the pointer to printf!

Jorge