Skip to content

Instantly share code, notes, and snippets.

@markandey
Created March 3, 2012 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markandey/1966813 to your computer and use it in GitHub Desktop.
Save markandey/1966813 to your computer and use it in GitHub Desktop.
Generate color rainbow list items
function getColor(noOfColors){
html="";
frequency=5/noOfColors;
for (var i = 0; i < noOfColors; ++i){
var xspan=(i%10)+2;
var yspan=Math.floor(i/10);
yspan=(1-yspan/2);
r = Math.sin(frequency*i + 0) * (127) + 128;
g = Math.sin(frequency*i + 2) * (127) + 128;
b = Math.sin(frequency*i + 4) * (127) + 128;
li='<li class="color" style="background-color:rgb({r},{g},{b});"> </li>';
li=li.replace("{r}",Math.floor(r));
li=li.replace("{g}",Math.floor(g));
li=li.replace("{b}",Math.floor(b));
html=html+li;
}
return html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment