@UlrikeFischer Here with your method:
\documentclass[tikz]{standalone}
\usetikzlibrary{shadings}
\begin{document}
\foreach \n in
{0,1,...,20}
{%
\begin{tikzpicture}[declare
function={flag(\x,\n)=0.2*cos(\x/(1+abs(0.1*(10-\n))));}]
\path (4.5,2) rectangle (9,7.1);
\draw [line width=15.1mm] plot[variable=\x,domain=0:360,samples=72]
({4.8+\x/90},{6+flag(\x,\n)}) ;
\draw [line width=15mm,white] plot[variable=\x,domain=0:360,samples=72]
({4.8+\x/90},{6+flag(\x,\n)}) ;
\fill[left color=gray, right color=gray,middle color=gray!50!white] ([xshift=-2mm]4.8,7.0)--++ (0,-4.8)--++(4mm,0)--++(0,4.8)--…