Giter VIP home page Giter VIP logo

boids's Introduction

Two dimensional implementation of Boids using SpriteKit and Swift 4.

Now with more emotes! ๐ŸŸ ๐Ÿ” ๐Ÿฆ„

Overview

Boids is an algorithm for simulating natural group flocking behavior. Flocking is an emergent behavior accomplished by applying a set of simple rules on autonomous agents, called "boids". Each boid operates independently, assessing its surrounding flock and adjusting its heading based on an evaluation of a set of basic rules.

Rules

The standard flocking rules:

1. Cohesion: Steer toward the average position of nearby agents

2. Alignment: Maintain a heading similar to the average heading of nearby agents

3. Separation: Steer away from agents that are close to avoid crowding

In addition to the standard flocking rules, I've added:

4. Bound: Steer away from the bounds of the device screen to keep agents in view

Interaction

A touch adds a temporary rule:

6. Seek: Move toward the current touch position

A force touch adds a temporary rule:

7. Evade: Move away from the current touch position

Preview

Usage

// Initialize and add a Boid SpriteNode to the Scene
let boid = Boid(withCharacter: "๐Ÿก", andSize: 40)
addChild(boid)
// Configure the boid's behaviors.. or don't; whatever, it's your life
self.behaviors = [Cohesion(intensity: 0.1), Separation(intensity: 0.1), Alignment(intensity: 1.0)]

Performance

Because each boid needs to iterate over the entire group, this runs in quadratic time O(nยฒ). As a benchmark, the iPhone X can maintain 60fps when simulating up to 150 boids.

Source Versioning

  • Xcode 10.1
  • iOS SDK 12
  • Swift 4.2

Credit

Original Paper: Craig W. Reynolds (1987). Flocks, Herds, and Schools: A Distributed Behavioral Model

Pseudocode: Conrad Parker (2007). Boids Pseudocode

boids's People

Contributors

christopherkriens avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

johndpope

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.