Created
March 2, 2013 04:34
-
-
Save coodoo/5069710 to your computer and use it in GitHub Desktop.
get random color in hex or rgba format.
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
/** | |
* @param useRGB Boolean, true for rgba format, false will return color in hex format | |
* @param randomAlpha Boolean, when using rgba format, decide whether to randomnize alpha value too | |
*/ | |
function getRandomColor( useRGB, randomAlpha ){ | |
if( useRGB ){ | |
return "rgba("+ | |
Math.floor(Math.random()*256)+","+ | |
Math.floor(Math.random()*256)+","+ | |
Math.floor(Math.random()*256)+","+ | |
(randomAlpha ? Math.random().toFixed(1) : 1) +")"; | |
} | |
return Math.floor(Math.random() * 0xFFFFFF).toString(16); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment