Particle Swarm Experiment 3

The little experiment now has multiple modes and a little system for sequencing them. I think this might be as far as I take this for now, but may end up coming back to it to add some new bits and pieces.

Particle Swarm 3

The code is pretty straightforward and development was made even quicker thanks to the awesome HYPE framework.  I wrote a custom particle class that is solely used to store numbers and calculate where it should go next (you pass it a target point and it swarms towards it) and the Main class generates and animates the 40 0000+ particles.

The Object Pool class from the HYPE Framework made working with large numbers of particles easy, though I think I could probably get greater performance from a custom solution.  Other than the maths to work out where a particle should go next the only other code worth noting is how a particle is drawn.

Experienced flash developers will know this like the back of their hands, but it's useful to document for newer developers that might now have had the exposure to manipulating large numbers of particles and drawing them to the screen.  It involves a large bitmap and the BitmapData class' setPixel32() method.

 

bmd.colorTransform(bmd.rect, new ColorTransform(1,1,1.02,0.99));  
bmd.applyFilter(bmd, bmd.rect, new Point(0,0), new BlurFilter(1.15, 1.15, 1));  
bmd.lock();  
pool.activeSet.forEach(function(p:Pixel):void{  
p.update();  
bmd.setPixel32(p.x, p.y , p.color);  
});
bmd.unlock()

 

Ian Thomas

Father of two, Husband and UI Engineer, currently working at Sky Betting and Gaming

Leeds

Subscribe to Ian Thomas

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!