Convert from setTimeout to requestAnimationFrame