Created
November 24, 2015 16:48
-
-
Save adamblank/75447ca3cc665ddf0d55 to your computer and use it in GitHub Desktop.
This little utility changes the "width" (i.e. of a progress bar) with sense of unpredictability. The obj implementation is just to make it generic-ish (was originally a React component method.) The only logic that's been tested is marked below as "the meat"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj = { | |
width: 0, | |
start() { | |
let extra = 0; | |
let interval = setInterval(() => { | |
if (width === 100) { | |
clearInterval(interval); | |
} | |
// the meat | |
if (Math.floor(Math.random() + 0.6)) { | |
this.width = this.width + (3 + extra) + (Math.floor(Math.random() * 6)); | |
extra = 0; | |
} else { | |
extra += 3; | |
} | |
}, 1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment