Skip to content

Instantly share code, notes, and snippets.

@azzlack
Last active August 29, 2015 14:14
Show Gist options
  • Save azzlack/b945f1a9b7a5c9393b5c to your computer and use it in GitHub Desktop.
Save azzlack/b945f1a9b7a5c9393b5c to your computer and use it in GitHub Desktop.
Create color from a string
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