Please see this accompanying article to learn more about this algorithm and the code. https://medium.com/better-programming/boids-simulating-birds-flock-behavior-in-python-9fff99375118
Note that the PySimpleGUI code will not be covered in the article as it's a new addition.
Can't wait to download and run the code?? Immediately see this code running in your browser window (albeit SLOWLY): https://repl.it/@PySimpleGUI/Boids-on-PySimpleGUI
Boids is an artificial life program developed by Craig Reynolds which simultes the flocking behaviour of birds.As with most artificial life simulations, Boids is an example of emergent behavior; that is, the complexity of Boids arises from the interaction of individual agents (the boids, in this case) adhering to a set of simple rules. The rules applied in the simplest Boids world are as follows:
- separation: steer to avoid crowding local flockmates
- alignment: steer towards the average heading of local flockmates
- cohesion: steer to move towards the average position (center of mass) of local flockmates
This fork of boid is a port to the PySimpleGUI framework. It is currently running on the tkinter and the browser ports. It alsmot ran on the Qt port (very close)
This repository is a fork of the Boids project located here: https://github.com/roholazandie/boids
The change to the code was removal of P5 as the graphic rendering engine and replaced with PySimpleGUI and PySimpleGUIWeb. With the addition of the GUI came a slider that enables you to adjust, in real time, the number of birds. Then came manipulation of more internal variables. Who knows what other fun you can add!
By the magic of PySimpleGUI this code is running both on the desktop in the form of a tkinter window but also it runs in the browser. The only required change to the program was the import statement. That's ALL you have to change to move from the desktop to the browser. Amazing.
import PySimpleGUI as sg
import PySimpleGUIWeb as sg
Run:
sudo apt-get install libglfw3
pip install -r requirements.txt
For using fast boid: (Not yet ported)
pip install ray
The implemented boid is slow for large number of boids. The fast_boid is a try usign ray to make it faster. In current implementation, it doesn't make a huge difference though. If someone could figure out to make it faster just send me a push request.