Skip to content

Instantly share code, notes, and snippets.

@adamblank
Created November 24, 2015 16:48
Show Gist options
  • Save adamblank/75447ca3cc665ddf0d55 to your computer and use it in GitHub Desktop.
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"
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