Inspired by Ben De Cock to use requestAnimationFrame for animation.