Created
May 4, 2012 05:04
-
-
Save jakebellacera/2592162 to your computer and use it in GitHub Desktop.
RGB to Hex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*---------------------------------------------------------- | |
RGB to HEX Converter | |
----------------------------------------------------------*/ | |
var hex = { | |
temp: { | |
chars: '0123456789ABCDEF', | |
partA: '', | |
partB: '', | |
output: '' | |
}, | |
generate: function(){ | |
this.temp.output = ''; // Cleanup | |
for( var i = 0; i < arguments.length; i++ ) { | |
partA = this.temp.chars.charAt( Math.floor( arguments[i] / 16 ) ); | |
partB = this.temp.chars.charAt( Math.floor( arguments[i] - ( Math.floor( arguments[i] / 16 ) * 16 ) ) ); | |
this.temp.output += partA + partB; | |
} | |
return '#' + this.temp.output; | |
} | |
}; | |
hex.generate(255,255,255); // #FFFFFF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment