Boids simulation implemented in Java using the LibGDX framework. https://ggrainger.epicpages.dev/libgdx-boids/
  • Java 93.6%
  • HTML 3.3%
  • CSS 3.1%
Find a file
George Grainger 24bce47857
All checks were successful
Publish to git pages / build (push) Successful in 1m56s
Update README.md
2026-06-14 20:22:53 +01:00
.forgejo Add git-pages deployment 2026-06-14 19:29:16 +01:00
core Add html project 2026-06-14 19:10:02 +01:00
desktop Increase starting resolution 2021-06-03 15:07:39 +01:00
gradle/wrapper Initial commit 2021-05-16 16:07:59 +01:00
html Hide superdev button 2026-06-14 20:19:20 +01:00
.gitattributes Replace preview.gif to fix framerate issue 2021-06-02 23:07:56 +01:00
.gitignore Initial commit 2021-05-16 16:07:59 +01:00
build.gradle Add html project 2026-06-14 19:09:56 +01:00
gradle.properties Initial commit 2021-05-16 16:07:59 +01:00
gradlew Add html project 2026-06-14 19:09:56 +01:00
gradlew.bat Initial commit 2021-05-16 16:07:59 +01:00
README.md Update README.md 2026-06-14 20:22:53 +01:00
settings.gradle Add html project 2026-06-14 19:09:56 +01:00

LibGDX-Boids

Build Status

A deployment of this simulation can be viewed here

Simulation in progress

Inspired by a video and similar project by Sebastian Lague.
His video can be found here.

The rules that define boids are given by a report he references, which can be found here.

What is a boid?

Boids are an algorithmic approach to simulation of flocking behaviour such as that found in flocks of birds or schools of fish.

They achieve this by following a series of simple rules which are defined in the report above and are as follows:

  • Collision Avoidance: Avoid collisions with nearby flock mates.
  • Velocity Matching: Attempt to match velocity with nearby flock mates.
  • Flock Centering: Attempt to stay close to nearby flock mates.

These are in order of decreasing presidence, meaning that Collision Avoidance is the most important, and Flock Centering is the least important.

Currently, this implementation handles avoidance of collisions with other objects, this is carried out by performing ray casts at increasing angles until an escape route can be found. The boid then turns towards this escape vector.

Spatial partitioning

In an attempt to improve performance of this boid implementation, we make use of spatial partitioning to prevent us from looping over every other boid for each frame, this implementation uses the underlying Box2D physics engine so that boids can only "perceive" other boids that are within a certain radius of them, this radius is defined in Constants.java.

Customising behaviour

The behaviour of the boids can be controlled by editing the values in Constants.java

The values in Constants.java can be adjusted during runtime using the options menu which can be opened with the button in the top left of the screen.
The values are not saved on program exit.

Running the simulation

The program can be run by downloading the Jar archive located in releases.
Java 11 is required in order to execute the program which you can do using the following command:

java -jar desktop-1.0.jar