tags:

views:

221

answers:

2

I have a function that returns a float from 0 to 255. I would like to make a gradient in red color from this, but I need a string in "#FFFFFF" format. Is there a function for that?

+7  A: 

You could use:

"#%02X0000" % x
Greg Hewgill
I'm now getting "not all arguments converted during string formatting" error. Tryed putting numbers instead of x, rounding x, truncating it, still the same error. Am I missing something?
akalenuk
It should be: "#%02X0000" % x (I.e. the "%" is missing).
PEZ
Thanks! Works fine now.
akalenuk
+1, now that it's fixed :)
Ali A
Whoops, thanks for that S.Lott. :)
Greg Hewgill
+3  A: 
def rgbtohex(r,g,b):
    return "#%02X%02X%02X" % (r,g,b)
FrozenFire