In this paper, we propose a decentralized control algorithm to solve the problem of shape formation in homogeneous swarms, which enables a swarm of agents to achieve a specific shape formation without collision. At the micro level, the algorithm makes each agent move to the desired shape domain without collision after receiving the shape information. At the macro level, the emergence of orderly formation swarm behavior is realized in this process. The Lyapunov method is used for the stability analysis of the agent swarm system. Simulation results demonstrate that the algorithm has strong flexibility, which can meet the formation requirements of various complex graphs such as convex, non-convex, connected and non-connected graph, and good adaptability to large-scale swarm.