I'm using Vivagraph JS library to render some graphs.
I would like to change the color of the node like this
nodeUI.color = 0xFFA500FF;
^ This is a random example. Not the corresponding hexadecimal value for RGB below
I get from server RGB values as an array like this
rgb = [229,64,51]
How do i convert RGB to the Hexadecimal type value metioned above?
Thanks
According to the comments in code here: https://github.com/anvaka/VivaGraphJS/blob/master/demos/other/webglCustomNode.html
The value 0xFFA500FF is a 32 bit value that includes an alpha channel, so ignoring the alpha channel it's equivalent to rgb(255,165,0).
Some functions to convert from 32 bit hex to 24 bit rgb and back are below, the comments should suffice to explain how they work.
Note that in the assignment:
the hex value 0xFFA500FF is immediately converted to decimal 11454440. To convert the result of fromRGBto32 to a number that can be assigned to odeUI.color, use parseInt:
or if you want to hard code it, just add '0x' in front.
If you have a string like 'rgb(229,64,51)', you can convert it to a hex value by getting the numbers, converting to hex strings and concatenating: