(a) Accumulation of bacterial suspension depletes oxygen in worm aggregates. Oxygen levels measured by the fiber optic sensor while the swarm passes through the sensor. Initially fiber optic sensor records ambient [O2] on the surface and the sudden drop is originating from the complete coverage of the fiber by the swarm body. (b) Oxygen-dependent motility of animals. The average speed of the worms as a function of ambient oxygen. The slope of the curve defines the aerotactic response of the animals. The comparison of velocity profiles of N2 (red) (on food), npr-1(blue) (on food), and off-food-N2 (green) response show the difference between the strains. Colored regions indicate the dispersive, stationary and aggregation phases. Error bar indicates the s.e.m. = ± 18 μm/s. For each experiment, 25 individual animals were imaged. Measurement error is defined by the error in image processing steps. (c) Schematic representation of each phase. The competition between animal dispersion (D) and aerotactic response (β) defines the collective behavior of worms. (d) Simulation results of the model at time 10 min after randomization of the patterns with various initial animal densities. The pattern formation strongly depends on worm density. At low density, worms create clusters. As the worm density increases, clusters converge to stripes and hole patterns. (e, f) Experimental results of density-dependent pattern formation. (e) At low worm densities (500 worms/cm2), N2 worms do not form patterns. As the density increases, we observed stripes (2000 worms/cm2) and holes (6000 worms/cm2). (f) The strong aerotactic response of npr-1 strain enables worms to form patterns even at low densities. An increase in the worm density causes a change in the instability conditions and tunes the patterns. Scale bar, 1 mm.