Uses sine wave to flap. Wave increases with distance from pole. Flags fall and rise in wind, so I added that effect.
I added the falling and rising to my earlier model (Ukrainian flag). I experimented until it looked right, and waved much less near the pole (amplitude and frequency decreases as x decreases). "America the Beautiful" performed by the Second Marine Aircraft Wing Band of Cherry Point, North Carolina (public domain)