I would first learn how to make a .gif animation, if you don't know how.
Key words, "How to make a .gif animation"
After you learn how to make a animation,
how use a gif animation as your desktop background on Debian by ckilmer75 » If it matters, I'm doing this in Raspbian via the Pixel desktop.
Well, it does , if I did go into details, and wrote a "How to", on this and for this forum, it would be for Debian, since this is a Debian User Forum,... and it probably would not work for some other OS, like Raspbian, or Pixels Desktop, .....
,...
Using a WM, OpenBox,on Debian 7 would be how I would write a script for,..
Would it work on Rasbpbian, and Pixels DE,..? I doubt it.
If you were using Debian, you could maybe use a package called .
"byzanz" (byzanz-record)
https://www.unixmen.com/make-animated-gif-screencasts-easily-byzanz/ Also Image Magick,
https://www.imagemagick.org/script/animate.php Or with the "convert" command, (what I used)
===========================================
https://www.imagemagick.org/Usage/anim_basics/#gif_anim=====================================================
Example:

Do some more searches, read some tutorials on "How to write a script "
But it would help get better results if you at least have some idea of what
kind of script, IE: bash, ksh,zsh,sh ,dash,perl,pascal,python,etc.....