Given a 256 value rgb vector, convert it to an hexadecimal number - Node.js Number

Node.js examples for Number:Decimal

Description

Given a 256 value rgb vector, convert it to an hexadecimal number

Demo Code


/**/*from w  w  w. j  a v a2s .c om*/
* Given a 256 value rgb vector, convert it to an hexadecimal number
*/
rgb2hex: function(r, g, b) {
    var  hs = Math.floor(r).toString(16);
    hs = hs.length == 1 ? "0" + hs : hs;
    var rs = hs;
    var  hs = Math.floor(g).toString(16);
    hs = hs.length == 1 ? "0" + hs : hs;
    var gs = hs;
    var  hs = Math.floor(b).toString(16);
    hs = hs.length == 1 ? "0" + hs : hs;
    var bs = hs;
    hs = "0x" + rs + gs + bs;
    return parseInt(hs);
},

Related Tutorials