Skip to content

Instantly share code, notes, and snippets.

@stephanbogner
Created June 22, 2021 12:59
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 stephanbogner/ba9da77e9b9620ef9771d4bf77ef296b to your computer and use it in GitHub Desktop.
Save stephanbogner/ba9da77e9b9620ef9771d4bf77ef296b to your computer and use it in GitHub Desktop.
Script to make a flickering with increasing frequency (think tak ...... tak .... tak ... tak .. tak . takkkkk ). Useful for when a timing is ending. I used this algorithm in combination with a shader for our GMTK Game Jam 2021 Game "Cursed Leash" (https://st-phan.itch.io/cursed-leash)
<script>
let counter = 0;
setInterval(function(){
counter += 0.03/8;
counter = Math.min(1, counter);
var y = Math.sin(counter * counter * counter * 80);
var bool = true;
if (y < 0) {
document.body.style.background = "grey";
bool = false;
}else{
document.body.style.background = "white";
}
console.log(counter, y);
}, 30)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment