Skip to content

Instantly share code, notes, and snippets.

@truongan
Last active August 1, 2019 07:15
Show Gist options
  • Save truongan/e4646480b7ab7509e8ce63eb7f507cfd to your computer and use it in GitHub Desktop.
Save truongan/e4646480b7ab7509e8ce63eb7f507cfd to your computer and use it in GitHub Desktop.
$(document).ready(function(){
function getColor(noOfColors){
html="";
frequency=5/noOfColors;
for (var i = 0; i < noOfColors; ++i){
r = Math.floor(Math.sin(frequency*i + 0) * (127) + 128);
g = Math.floor(Math.sin(frequency*i + 2) * (127) + 128);
b = Math.floor(Math.sin(frequency*i + 4) * (127) + 128);
li='<li class="color" name="' + i.toString() + '" style="background-color:#{r}{g}{b};"> </li>';
li=li.replace("{r}",r.toString(16).padStart(2,'0'));
li=li.replace("{g}",g.toString(16).padStart(2,'0'));
li=li.replace("{b}",b.toString(16).padStart(2,'0'));
// console.log(li);
html=html+li;
}
console.log(html);
return html;
}
document.getElementById('rainbow').innerHTML=getColor(16);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment