Skip to content

Instantly share code, notes, and snippets.

@herrfugbaum
Created March 11, 2016 10:09
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save herrfugbaum/7a6530908899969446ac to your computer and use it in GitHub Desktop.
Return a random pastel rgba color.
/* @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