Beam shaping is of significance for applications in various fields, including laser fusion, laser processing, and optical manipulation. One conventional approach for beam shaping is using the superposition of eigenmodes, such as the Hermite-Gaussian (HG) modes. However, despite the generation of a flat-top beam by HG modes with identical coefficients, it is challenging to achieve other specific intensity distributions by this method. In this study, we validate the feasibility of the beam patterns modulation by optimizing the coefficients of the superimposed modes using an optimization algorithm. Beyond producing square flat-top spots with controllable size and intensity, this method can also achieve specialized intensity distributions including hollow square spots.