Created
May 29, 2013 17:01
-
-
Save dhoko/5671907 to your computer and use it in GitHub Desktop.
Convert color
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
var color = { | |
rgb : function() { | |
var color = [Math.floor(Math.random()*256),Math.floor(Math.random()*256),Math.floor(Math.random()*256)]; | |
return 'rgb('+color.join(',')+')'; | |
}, | |
rgb2Hex : function(color) { | |
var hex = "#", | |
c = color.split('(')[1].split(')')[0].split(','); | |
hex += parseInt(c[0]).toString(16)+parseInt(c[1]).toString(16)+parseInt(c[2]).toString(16); | |
return hex; | |
}, | |
hex : function() { | |
return '#'+Math.floor(Math.random()*16777215).toString(16); | |
}, | |
hex2rgb : function(color) { | |
var str = color.split('#')[1], | |
c = [str.substr(0,2),str.substr(2,2),str.substr(4,2)]; | |
return 'rgb('+parseInt(c[0],16)+','+parseInt(c[1],16)+','+parseInt(c[2],16)+')'; | |
}, | |
fromPicker : function(o) { | |
return 'rgb('+o.r+','+o.g+','+o.b+')'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment