var colors = { rainbow: ['red', 'orange', 'yellow', 'green', 'blue', 'purple'], qual: ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f'], quant: ['#fff7ec', '#fee8c8', '#fdd49e', '#fdbb84', '#fc8d59', '#ef6548', '#d7301f', '#b30000', '#7f0000'], div: ['#67001f','#b2182b','#d6604d','#f4a582','#fddbc7','#f7f7f7','#d1e5f0','#92c5de','#4393c3','#2166ac','#053061'] }; randc = function(array) { return array[Math.random() * array.length | 0] } genc = function() { var frag = []; var arr = colors[$("select").val()]; for (var i = 0; i < 1024; i++) { frag.push("<div style='background-color:" + randc(arr) + ";'></div>"); } $("#demo").html(frag.join('')); } genc(); $("select").on("change", genc);
#demo { margin-top: 10px; font-size: 0; } #demo div { display: inline-block; width: 24px; height: 24px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select> <option value='qual'>Qualitative (categorical)</option> <option value='quant'>Quantitative (sequential)</option> <option value='div'>Divergent (republicans versus democrats)</option> <option value='rainbow'>Rainbow (my little pony)</option> </select> <div id='demo'></div>