This could be done frame by frame e.g. using Photoshop, then export a video or a GIF.
In Illustrator you could do it as well, exporting a GIF using the plugin GIFStudio.
Or you could use Animate or After Effects.
It would primarily depend upon the output format you want to have.