Modified from Shiffman's flocking example for Nature of Code Book.