Skip to content

Instantly share code, notes, and snippets.

@mrlubos
Last active July 15, 2016 01:39
Show Gist options
  • Select an option

  • Save mrlubos/4edc933ae216d9ecabe783a2c013d4e1 to your computer and use it in GitHub Desktop.

Select an option

Save mrlubos/4edc933ae216d9ecabe783a2c013d4e1 to your computer and use it in GitHub Desktop.
// Points to the line in the array that is being animated.
var pointer = -1;
// Our copy of the line - we are free to do with it whatever we please.
var line = '';
// Holds the reference id to the active interval.
var interval;
// Starts the animation.
interval = setInterval(function () {
// Our copy of the line is empty.
if (line.length === 0) {
// Move the pointer to the next line.
pointer = pointer + 1;
// The pointer is inside the range, copy the new line.
if (pointer !== strings.length) {
line = strings[pointer];
}
// The pointer is out of range, stop the animation,
// reset the interval variable, and exit the loop.
else {
return interval = clearInterval(interval);
}
}
// Print the first character from our copy of the line.
app.print(line[0]);
// Now delete the first character, so the second character
// becomes the first, the third becomes second, etc.
line = line.substr(1);
// If we have reached the end of the line, fake the
// Enter key press action.
if (!line) {
app.println();
}
}, 80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment