Animation function that uses requestAnimationFrame