Skip to content

Instantly share code, notes, and snippets.

@keesey
Last active December 27, 2015 10:09
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 keesey/7308888 to your computer and use it in GitHub Desktop.
Save keesey/7308888 to your computer and use it in GitHub Desktop.
var CHANCE_OF_LIGHTNING = 1 / 100; // Tweak this.
var TOTAL_FRAMES = 4; // Include 'still' frame and lightning frames.
this.stop();
this.addEventListener('tick', function()
{
if (Math.random() < CHANCE_OF_LIGHTNING)
{
this.gotoAndStop(Math.floor(Math.random() * (TOTAL_FRAMES - 1)) + 1);
}
else
{
this.gotoAndStop(0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment