Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created July 13, 2010 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bebraw/474238 to your computer and use it in GitHub Desktop.
Save bebraw/474238 to your computer and use it in GitHub Desktop.
this.toHex = function () {
function RGBtoHex(a) {
function decimalToHex(d) {
var ret = d.toString(16).split('.')[0];
if( ret.length < 2 ) {
return 0 + ret
}
return ret.slice(0, 2);
}
return decimalToHex(a[0]) + decimalToHex(a[1]) + decimalToHex(a[2]);
}
return '#' + RGBtoHex([this.r, this.g, this.b]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment