21. December 2024
This is a simple program illustrating flocking mechanisms and the effect of a vector field that changes over time. In the past I have done a lot of experimenting with particle systems and vector fields and how particles interact with one another with different forces. This is largely due to Daniel Shiffmans excellent The Coding Train (formerly The Coding Rainbow) Youtube-Channel in which he teaches programming in a very applied and diverse way by solving challenges. Through this series I initially learned programming and can recommend it to everyone, even now, as a continuous source of interesting areas of programming.
In this flocking simulation 4 forces are at work
With each of these fundamental forces comes at least one constant, used to scale their effect. This makes getting realistic flocking behavior, as seen in flocks of birds for example, pretty difficult. As a rule of thumb I found that the attraction constant should be larger than the repelling constant. It is very important that the repelling force falls of quicker than the attracting force since we want particles that are far apart to move towards each other to form groups. Without a repelling force all particles would just bundle up into a single point and it would be uninteresting. This is almost exactly the same as the balance of electrical and gravitational forces in particles.
An image of the particles being moved by the vector field without any flocking forces being active. This can create stunning imagery if done right and I hope I get to showcase this project soon.