Skip to content

Instantly share code, notes, and snippets.

@sukkamehu
Created February 26, 2021 10:06
Show Gist options
  • Save sukkamehu/3da0f723f67b126beb4ebd828daf74e2 to your computer and use it in GitHub Desktop.
Save sukkamehu/3da0f723f67b126beb4ebd828daf74e2 to your computer and use it in GitHub Desktop.
Rainbow
<body style="background-color: #fff"></body>
<script>
(function() {
let body = document.getElementsByTagName("BODY")[0];
let red = 0;
let green = 0;
let blue = 0;
setInterval(function(){
switch(blue) {
case 255:
console.log("reset")
red = 0;
green = 0;
blue = 0;
break;
}
switch(green) {
case 255:
blue++
console.log("adding blue")
break;
}
switch(red) {
case 255:
if(green < 255){
green++
console.log("adding green")
}
break;
default:
red++;
console.log("adding red")
}
let current = 65536 * red + 256 * green + blue
let rgb = Number(current).toString(16).toUpperCase()
body.style.backgroundColor = rgb;
},20)
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment