Any periodic function can be approximated as the sum of a sine (or cosine) with the same period, plus appropriate amounts of its harmonics. Here a square wave is constructed from cosines - only the odd harmonics of the fundamental frequency are used in this case, but that would not always be true for other shapes.