Space swarms, enabled by the miniaturization of spacecraft, have the potential capability to lower costs, increase efficiencies, and broaden the horizons of space missions. The formation control problem of large-scale spacecraft swarms flying around an elliptic orbit is considered. The objective is to drive the entire formation to produce a specified spatial pattern. The relative motion between agents becomes complicated as the number of agents increases. Hence, a density-based method is adopted, which concerns the density evolution of the entire swarm instead of the trajectories of individuals. The density-based method manipulates the density evolution with Partial Differential Equations (PDEs). This density-based control in this work has two aspects, global pattern control of the whole swarm and local collision-avoidance between nearby agents. The global behavior of the swarm is driven via designing velocity fields. For each spacecraft, the Q-guidance steering law is adopted to track the desired velocity with accelerations in a distributed manner. However, the final stable velocity field is required to be zero in the classical density-based approach, which appears as an obstacle from the viewpoint of astrodynamics since the periodic relative motion is always time-varying. To solve this issue, a novel transformation is constructed based on the periodic solutions of Tschauner-Hempel (TH) equations. The relative motion in Cartesian coordinates is then transformed into a new coordinate system, which permits zero-velocity in a stable configuration. The local behavior of the swarm, such as achieving collision avoidance, is achieved via a carefully-designed local density estimation algorithm. Numerical simulations are provided to demonstrate the performance of this approach.