This is a p5.js sketch which explores the idea that the movement pattern of animals in a herd in response to a predator can be modeled using a Voronoi diagram, whereby any given animal will ensure there is another animal is between it and the predator.
This was primarily inspired by John D. Barrow’s chapter on herding.
Click & Dragwill move the yellow circle which denotes the predator.
herd_countis the number of members of the herd.
member_sizeis the pixel size of the individual herd members.
drawVoronoitoggles the display of the lines the denote mid-point between members that are neighbors.
wrapEdgestoggles whether or not the members will be bound by the edges of the window, or can wrap around to the opposite edge.
maxSpeed- How quickly the members can move.
desiredSeparationHow far apart the members want to be.
- From Ch. 84 of: 100 Essential Things You Didn’t Know You Didn’t Know About Maths & The Arts (books.wwnorton.com) by John D. Barrow
- Wikipedia: Voronoi Diagram
- Wikipedia: Vornoi, Georgy (Mathematician)
- GitHub: p5.voronoi library