Convert rgb to hex colour in python
For some things, like the tile colour of a node, you can’t work with rgb but need to use hex values instead. You can use the following code to convert rgb to hex:
1 |
hexColour = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,1),16) |
So, to set a random tile colour for the selected node, type:
1 2 3 4 5 6 7 |
import random n = nuke.selectedNode() r = (float(random.randint( 20, 40)))/100 g = (float(random.randint( 10, 50)))/100 b = (float(random.randint( 15, 60)))/100 hexColour = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,1),16) n['tile_color'].setValue( hexColour ) |
Random colour values in python Split file path in TCL