Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.