Last active
August 29, 2015 14:14
-
-
Save azzlack/b945f1a9b7a5c9393b5c to your computer and use it in GitHub Desktop.
Create color from a string
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 colors = [ | |
"8dd3c7", | |
"ffffb3", | |
"bebada", | |
"fb8072", | |
"80b1d3", | |
"fdb462", | |
"b3de69", | |
"fccde5", | |
"d9d9d9", | |
"bc80bd", | |
"ccebc5", | |
"ffed6f" | |
]; | |
var getColor = function (str) { | |
// Get integer from str | |
// seedrandom() is an extension from https://github.com/davidbau/seedrandom | |
var rnd = new Math.seedrandom(str); | |
// Taken from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ | |
var index = Math.round(rnd() * (colors.length - 1)); | |
return "#" + colors[index]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment