This popular video on YouTube shows in a fascinating way how a swarm builts a pattern from individuals which react on the behaviour of their local environment.
Here you can find a swarm simulation, links for this topic and explanations by Craig Reynolds:
Reynolds, Craig (1987), “Flocks, herds and schools: A distributed behavioral model.”, SIGGRAPH ’87: Proceedings of the 14th annual conference on Computer graphics and interactive techniques (Association for Computing Machinery): 25–34.
Grimm, V. 1999. Ten years of individual-based modelling in ecology: what have we learned and what could we learn in the future? Ecological Modelling 115:129-148.
DeAngelis, D.L. & W.M. Mooij. 2005 Individual-based modeling of ecological and evolutionary processes. Annual Reviews in Ecology, Evolution and Systematics 36: 147-168.
Grimm, V., Railsback, S. F. (2005) Individual-based modeling and ecology Princeton series in theoretical and computational biology. Princeton University Press, Princeton, 428 S.
Grimm, V. (2008) Individual-based models. In: Jorgensen, S. E., Fath, B. D. (Hrsg.): Ecological Models. Encyclopedia of ecology Vol. 3, Elsevier, Amsterdam, S. 1959-1968.