Giter Club home page Giter Club logo

boids's Introduction

HTML5 Boids

HTML5 implementation of the boids model of coordinated animal motion.

The model

Boids is a computer model of coordinated animal motion such as bird flocks and fish schools. The model consists of three simple rules that describe how an individual boid moves based on the positions and velocities of its nearby boids:

  1. Collision avoidance: point away from the k nearest boids.
  2. Flock centering: point towards the perceived center of mass of the k nearest boids.
  3. Velocity matching: update velocity to the average of the k nearest boids.

Note that this implementation is a little different from the original model, and doesn't aim to recreate the exact same behavior. This aims to be an HTML5 visualization of the model that is configurable and performs well with as many boids as possible. The code is open source and - hopefully - easy to read and tweak.

The original model was developed by Craig Reynolds.

Implementation

It's all written in coffeescript, a language that compiles into javascript. To improve performance, I used a kd-tree for answering queries of the type "what are the K nearest points to point P". The kd-tree and the binary heap it requires are also written in coffeescript.

Tweaking

You can configure the simulation to some extend without touching the code or leaving your browser. Click on the option button to the right and you will be presented with certain configuration options that can significantly alter the boids' behavior. Here's a more detailed explanation of the sliders:

  • Number of boids: The number of boids on the screen. Decreasing this can improve performance significantly.
  • Simulation speed: Increasing this value too much will result in decreased accuracy.
  • Acceleration factor: How fast the boids can accelerate. A high value will make the boids behave more like fish.
  • Flock size: The number of neighboors boids will consider to calculate the center of mass and flock velocity.
  • Importance factors: Each of the four rules (three from the model, and an additional rule to keep the boids in the screen) has an associated weight. The higher the weight, the more important the rule is considered.

boids's People

Watchers

James Cloos avatar Bernard Lim 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.