How to do a square spline

I want to make a square wave spline to use it as a guide for a rectangle, how to do it?

Can you provide a visual prototype or an example for what you want to achieve?