npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

swarmz.cxx

v1.0.0

Published

A free, header-only C++ swarming (flocking) library for real-time applications; Michael (2016).

Readme

Swarmz

A free, header-only C++ swarming (flocking) library for real-time applications, by Michael.

An example usage can be seen in this particle editor plugin for the Unreal Engine 4.

Installation

Run:

$ npm i swarmz.cxx

And then include swarmz.h as follows:

#include "node_modules/swarmz.cxx/swarmz.h"

Usage

Just include the header file to start:

#include "swarmz.h"

using namespace sw;

To create a new swarm, a pointer to the list of Boids is required. A boid is a single member of the swarm. Each boid has a position and a velocity:

// define our swarm members
vector<Boid> boids;
boids.push_back(Boid(Vec3(1, 0, 0), Vec3(1, 0, 0)));
boids.push_back(Boid(Vec3(1.5, 0, 0), Vec3(1, 1, 0)));
boids.push_back(Boid(Vec3(1, 0.5, 0.5), Vec3(0, 1, 0)));
boids.push_back(Boid(Vec3(4, 4, -2), Vec3(1, 0, 0)));

//create the swarm!
Swarm swarm(&boids);

The swarm has a lot of different settings, but the most important ones are the following:

  • PerceptionRadius - determines the vision radius of each boid. Only boids within this distance influence each other.
  • SeparationWeight - how much boids repel each other
  • AlignmentWeight - how much boids want go in the same direction
  • CohesionWeight - how much boids want to be in the center of the swarm
  • MaxAcceleration - how fast each boid can change its direction
  • MaxVelocity - how fast each boid can move

Each setting has a sensible default parameter, but playing around with them is half the fun:

// configure swarm
swarm.PerceptionRadius = 100;
swarm.CohesionWeight = 0.2;

To calculate the swarm movement, you usually update the swarm a few times a second in a loop. The swarm does not automatically move the boids, it just updates the velocity and acceleration for each boid. The position has to be updated by you.

// your tick/update loop
while (true) {
  swarm.Update(deltaSeconds);
  
  // each boid now has an updated velocity
  for (auto& boid : boids) {
    // update position
    boid.Position += boid.Velocity * deltaSeconds;
    
    // draw boid
  }
}

If you do not want the swarm to even update the boids velocity automatically (because you want to debug the result or you want to scale the acceleration per boid), then you can just call UpdateAcceleration() instead of the Update(deltaSeconds) on the swarm.

You can of course adjust the swarm parameters as well as the boid list during the loop to change the swarm behaviour over time. The library is, however, not thread-safe (so please no changes during the swarm update)!

That's basically it, have fun! :)

ORG