Overview
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.
Controls
Mouse
Click & Drag
will move the yellow circle which denotes the predator.
Configuration Options
herd_count
is the number of members of the herd.member_size
is the pixel size of the individual herd members.drawVoronoi
toggles the display of the lines the denote mid-point between members that are neighbors.wrapEdges
toggles whether or not the members will be bound by the edges of the window, or can wrap around to the opposite edge.- Flocking:
maxSpeed
- How quickly the members can move.desiredSeparation
How far apart the members want to be.
References:
- 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
- Flocking
- Craig Reynolds: http://www.red3d.com/cwr/
- Dan Shiffman, GitHub: Nature of Code: Flocking
- Wikipedia: Boids