Flocking Simulator example for MED8 Algorithms, Data Structures and Software Engineering course
This repo contains two example of flocking:
ADSSE_Flocking.ipynb, A Jupyter Notebook project written using numpy and animated using Matplotlib. This can be run on binder, (although the HTML animations may not work):- A real time example written with the P5 library. P5 is a useful tool, though can be difficult to set up (instructions below).
This demo uses p5py, which is a python port of the javascript library p5js (which is in turn based on processing). In order to use p5py, we first need to install the Graphics Library Framework (GLFW).
For mac users it is easy to install this
brew install glfw
Likewise, it is easy to install GLFW on most linux systems:
sudo apt-get install libglfw3
Unfortunately it is not so easy to install GLFW on windows. Try the following steps:
- Download the latest version of GLFW from this link: https://www.glfw.org/download.html
- Note: I recommend getting the 32-bit binaries, even though you are likely on a 64-bit system (this is simply the only way it worked for me)
- Extract the to an easy to find location (e.g.
C:\GLFW\). It is most important to ensure to this folder now contains\include\and\lib-mingw\ - Open the command prompt as an administrator
- Open the start menu and type "cmd"
- Right-click on "Command Prompt"
- Select "Run as administrator"
- Enter the command
python -m pip install -U --force glfw-cffi
GLFW is now installed, but you still have to add it to the system environment, so that it can be used.
- Locate the Environment Variables window
- Open the Control Panel and navigate to the System panel
- On the left, click on "Advanced System Settings"
- In the pop-up window, selecet "Environment Variables"
- Create a new user variable
- Name it
GLFW_LIBRARYand set the value toC:\GLFW\lib-mingw\glfw3.dll, or whatever the equivilant directory address for that file is on your device. - Select OK on all the open menus, then you are ready to install p5
- Open CMD or a python terminal and run the command
pip install p5- Note: if this gives you permission errors, try either
pip install p5 --userorpython -m pip install p5
- Note: if this gives you permission errors, try either
Now you should be able to run the p5 example. Navigate to the project directory in a command line window and use the command python main.py to run it. Try changing some parameters in the code to see what the effects are.