Giter Site home page Giter Site logo

rystrauss / boids Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 6.0 28.03 MB

Craig Reynolds' Boids model for simulating the flocking behavior of birds.

License: MIT License

CMake 1.43% C++ 98.47% Shell 0.10%
boids emergent-behavior flocking artificial-life swarm-intelligence murmuration kd-tree

boids's Introduction

Boids

Boids is a program developed by Craig Reynolds in 1986, which simulates the flocking behaviour of birds. He published this model in 1987 in the seminal paper "Flocks, Herds, and Schools: A Distributed Behavioral Model".

The motion of a flock of birds is an example of emergent behavior -- each bird is only making individual decisions, yet the motion of the entire flock is fluid and synchronized. Somehow, organized group behavior is able to emerge as the aggregate of the local actions of each individual animal.

Boids simulates this individual decision making with three rules:

  1. Separation: individuals try to avoid crowding their nearby flockmates
  2. Alignment: individuals steer towards the average heading of nearby flockmates
  3. Cohesion: individuals try to move towards the center of mass of nearby flockmates

This repository contains an implementation of the boids model in C++.

Simulation Example

Implementation Details

This implementation uses a k-d tree to increase efficiency. A k-d tree partitions the boids in space so that when each boid is updated, we only consider the nearby boids rather than iterating over all boids and incurring an O(n2) cost.

The implementation also uses OpenMP for some simple parallelization that leads to further speedups (and therefore the ability to simulate a larger number of boids).

Usage

This project depends on SFML, which must be installed first. On MacOS, this can be done with brew install sfml.

After installing SFML, the executable for the program can be built and installed by running the script build_and_install.sh. This program can then be run with:

./bin/simulate

Almost all aspects of the simulation and the boids' behavior can be customized from the command line. Pass the --help flag to see available options.

The simulation is also interactive. Left-clicking on the screen will add a new boid, and right-clicking will add a new predator boid (normal boids will try to avoid these). Pressing C on the keyboard will clear all the Boids on the screen, and pressing Q will end the simulation and quit the program.

boids's People

Contributors

prakash-shekhar avatar rystrauss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.