Code Monkey home page Code Monkey logo

flocking-simulation's Introduction

Flocking Simulation

A 3D Boids-like flocking simulation coded in Haskell.

Bulding

Assuming you have GHC 7.10 and stack installed, building the program should be as easy as running stack build.

You can then run the simulation with the command stack exec boids.

Demo and Screenshots

Here is a video demonstrating a typical run with the default configuration.

This is just after starting the program, when the boids are beginning to organize into groups. Screenshot

After running for a while, much larger groups of boids form. Screenshot

Usage

The controls are very simple:

Click and drag with the mouse to move the camera around.
Use the 'w' and 's' keys to zoom in and out.
Quit the application by pressing 'q', the escape key, or closing the window.

Details

As stated above, the entire program is written in Haskell in a purely functional style. To do 3D rendering, I use the newly released GPipe 2 library which creates a type safe way to interface with OpenGL 3.3. GPipe also provides a DSL for writing shaders, so all the shader code is written in Haskell as well.

The main data structure used to keep track of and efficiently update the boids is an octree. Every frame, the octree is flattened to a list and each boid is updated. This action is performed in parallel using all available CPU cores. The list of updated boids is then used to build a new octree (also in parallel), and the boids are rendered. I suspect that there's a lot of room for efficiency improvements by switching the lists in this process to vectors. That change would also (I think) allow me to utilize the Repa library and push boid updating to the GPU, potentially resulting in an enormous increase in the number of boids I'm able to simulate.

TODO List

Here are some things I'd like to improve (in no particular order):

* Replace lists with vectors
* Add predators and prey
* Integrate with the Repa library to exploit GPU parallelization
* Add a GUI and allow customizable parameters on the fly
* Add more sophisticated boid behavior
* Optimizations!

flocking-simulation's People

Contributors

chase-c avatar drdub avatar

Watchers

James Cloos avatar Edvan Sousa 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.