I demonstrate a basic three-rule model for flocking behaviour in a school of fish. You can find the Matlab codes here.
My simulations show the well-known fact that when individual virtual fish adapt their behaviour to that of their neighbours, the whole school of fish starts to move in a synchronised way. I took the most typical rules from the literature on flocking models: (1) Do not bump into others; (2) Stay close to your neighbors, and (3) Align your swimming direction to that of the neighbours.