My Male Betta had the same problem, Calab. I have a 5g Hex tank and he was freaking out. Same idea, up and down the seams, flaring most of the time. I tried to put a background around 3 of the sides and that didn't help at all.
What I did find that helped were fake plants. I put two into his tank. These two covered the primary seams that he did his little act on. In addition, time helped.

Just being patient and letting him get used to his home. He doesn't do it much anymore. From time to time he will if the ambient lights in the room are out and only his tank light is on, but even then not so much anyymore.
Hope that helps!