Skip to content

🐝 Particle swarm optimization method, animated in DOM w/GPU acceleration.

License

Notifications You must be signed in to change notification settings

ytiurin/particleswarm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo GIF

Particle swarm 🐝 Watch in action

Particle swarm is an optimization method that iteratively improves a candidate solution with regard to a given measure of quality. Check the Wikipedia page for algorithm description.

Usage

This code defines a particle swarm object, containing 10 particles with random position.

// Create swarm
var swarm = new Swarm;
// Configure particles movement
swarm.particleBraking = 0.997;
swarm.maxSpeed = 50;
// Set swarm target and bound 
// particles allowed position
swarm.targetPosition = new Vector( 100 / 2, 100 / 2 );
swarm.boundingRect = [ new Vector, new Vector( 100, 100 ) ];
// Set number of particles
var particlesCount = 10;
// Create particles
while ( particlesCount-- )
  swarm.addParticle(
    new Particle(
      new Vector( Math.random() * 100, Math.random() * 100 )));
// move particles 60 times per second
setInterval(function(){
  swarm.next()
}, 16);

GPU acceleration

Animated elements are transformed using CSS translate3d/rotate3d properties, which is GPU accelerated in majority of modern browsers.

About

🐝 Particle swarm optimization method, animated in DOM w/GPU acceleration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published