In this study, we focused on robotic swarms, allowing multiple anonymous autonomous robots to gather and move mutually in tasks. We proposed a method to design a parameter of the control barrier function (CBF) in a robotic swarm so that the swarm can achieve collision-free deformation considering the environmental conditions. We analyzed the responses to perturbations of swarming robots, to which we applied the CBF. Although we can guarantee a safe distance between mobile robots, the CBF limits their actions and prevents swarm deformation. Through analysis of the frequency domain, we investigated the effects of a selected parameter in the CBF on the deformability of a swarm. We obtained an appropriate range of parameters that realize both distance maintenance and deformability retention.