Created
March 11, 2016 10:09
-
-
Save herrfugbaum/7a6530908899969446ac to your computer and use it in GitHub Desktop.
Return a random pastel rgba color.
This file contains hidden or 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 alpha boolean | |
* if true a random value for the alpha channel is calculated, else alpha channel = 1 (full saturation) | |
*/ | |
var randomPastelColor = function (alpha) { | |
var rndm = function (f) { return Math.floor(Math.random() * f)}, | |
pstlfy = function (p) { return Math.round((p + 255) / 2)}, | |
r = pstlfy(rndm(256)), | |
g = pstlfy(rndm(256)), | |
b = pstlfy(rndm(256)), | |
a = alpha ? rndm(11) / 10 : 1 | |
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment