akalenuk
akalenuk

Reputation: 3845

How to make a color from a number

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?

Upvotes: 5

Views: 2441

Answers (2)

edef
edef

Reputation: 752

def rgbtohex(r,g,b):
    return "#%02X%02X%02X" % (r,g,b)

Upvotes: 3

Greg Hewgill
Greg Hewgill

Reputation: 994251

You could use:

"#%02X0000" % x

Upvotes: 12

Related Questions