https://github.com/aramshiva/boids
🦅 Artifical Swarm Intelligence
https://github.com/aramshiva/boids
art boids generative math numpy pygame python swarm
Last synced: 11 months ago
JSON representation
🦅 Artifical Swarm Intelligence
- Host: GitHub
- URL: https://github.com/aramshiva/boids
- Owner: aramshiva
- License: apache-2.0
- Created: 2025-01-20T02:16:16.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-30T01:19:58.000Z (12 months ago)
- Last Synced: 2025-03-10T20:54:26.608Z (11 months ago)
- Topics: art, boids, generative, math, numpy, pygame, python, swarm
- Language: Python
- Homepage: https://boids.aram.sh
- Size: 51.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Boids!
Boids is an artificial life program, developed by [Craig Reynolds](https://www.red3d.com/cwr/) in 1986, which simulates the flocking behaviour of birds, and related group motion.
Boids uses three simple rules to work accurately:
- 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
### TL;DR Boids is a program that can create really cool swarm intelligences and can simulate basically real flocks of birds, schools of fish and stuff like that.
## Technology
-The visual/graphics run on [`pygame`](https://pygame.org) (An python library to make 2D graphics.python) to run the visuals.
- [`numpy`](https://numpy.org/) is used to run more complex mathmatical calculations to caclulate boids three rules.
- [`GitHub Copilot`](https://github.com/features/copilot) was used to optimize my bad math calculations + adding multithreading.
## Run it Yourself!
That's cool and all but how do I run it myself?
> [!WARNING]
> This code uses a lot (~1GB) of RAM and threads. This is due to how the optimization techniques work and I do not guarantee it will work on your local machine, if it doesn't post a GitHub issue but I can't promise anything
- Make sure you have [Python](https://www.python.org/) installed.
- Next, clone the repo and move to that directory.
- Run:
```
pip install -r requirements.txt
```
- Last, run `python3 main.py`!
### Controls
- `R` - Add boids
- `CLICK` - Add boid
- `-` - Remove boids
- `B` - Change boid mode (different filters and styles!)
- `C` - Change color of boids
- `G` - Change boid vision type
- `V` - Show boid vision
### Change stats
Well, the code is open-source! So you can play around with it, if you want a low-code solution check out the ALL CAPS variables at the top of `main.py` to edit them, the names are pretty self explanatory. Here are the defaults:
```
COLORS = {"BLUE": (12, 18, 226),"RED": (255, 0, 0),"GREEN": (0, 255, 0),"YELLOW": (255, 255, 0),"ORANGE": (255, 165, 0),"PURPLE": (128, 0, 128),"PINK": (255, 192, 203),"CYAN": (0, 255, 255),"WHITE": (255, 255, 255),"BLACK": (0, 0, 0),"GRAY": (128, 128, 128),"BROWN": (165, 42, 42), "GRAY": (128, 128, 128)}
HEIGHT = 750
WIDTH = 1250
BG_COLOR = (255, 255, 255)
VISION_COLOR = (200, 200, 200)
SHOW_VISION = False
BOID_SIZE = 5
BOID_TYPE = "lights"
VISION_RADIUS = 20
BOIDS_COUNT = 1000
TRANSPARENCY_VALUE = 5
BOID_COLOR = COLORS["RED"]
```
To change a color use an RGB format, some preset colors can be pasted in:
- `COLORS["BLUE"]`
- `COLORS["RED"]`
- `COLORS["GREEN"]`
- `COLORS["YELLOW"]`
- `COLORS["ORANGE"]`
- `COLORS["PURPLE"]`
- `COLORS["PINK"]`
- `COLORS["CYAN"]`
- `COLORS["WHITE"]`
- `COLORS["BLACK"]`
- `COLORS["GRAY"]`
- `COLORS["BROWN"]`