Simulating Bird/Fish Flocking (Python)
For my second (and hopefully last) project in Python, we had to simulate flocking behavior, as outlined in Craig Reynolds' post.
More Python Challenges
Since I don't have much experience with Python, again the majority of this project was learning the language. I used a very helpful graphics library for python called pygame, which has a lot of capability for such a simple library. Also, I discovered that Python is a lot more annoying when it comes to having multiple files and importing the classes in such files into the main class. With some help from my classmates, I learned that Python has support from <File> import <Class> which removed the need to call <File>.<Class> every time I needed to access an imported class.
Flocking Behavior
The behavior itself is relatively simple. As Craig outlines in his post listed above, the main behaviors of flocking consist of cohesion, separation, and alignment. Cohesion is the behavior that brings boids (the term for the object that is flocking) together. Separation is the opposite; it keeps boids away from each other. Alignment does exactly what it sounds like: the boid aligns itself according to other boids around it. Each boid has a neighborhood, or a radius around itself, for which it takes into account other boids. If there are no other boids within said neighborhood, the boid will continue straight. However, when a boid enters the neighborhood, the three aforementioned behaviors come into play.
More Python Challenges
Since I don't have much experience with Python, again the majority of this project was learning the language. I used a very helpful graphics library for python called pygame, which has a lot of capability for such a simple library. Also, I discovered that Python is a lot more annoying when it comes to having multiple files and importing the classes in such files into the main class. With some help from my classmates, I learned that Python has support from <File> import <Class> which removed the need to call <File>.<Class> every time I needed to access an imported class.
Flocking Behavior
The behavior itself is relatively simple. As Craig outlines in his post listed above, the main behaviors of flocking consist of cohesion, separation, and alignment. Cohesion is the behavior that brings boids (the term for the object that is flocking) together. Separation is the opposite; it keeps boids away from each other. Alignment does exactly what it sounds like: the boid aligns itself according to other boids around it. Each boid has a neighborhood, or a radius around itself, for which it takes into account other boids. If there are no other boids within said neighborhood, the boid will continue straight. However, when a boid enters the neighborhood, the three aforementioned behaviors come into play.
Comments
Post a Comment