Flocking
Flash required: You need version 9 or later of the free Flash player from Adobe to use this content. To download and install the free player from Adobe’s web site click here.
Source code
This uses many of the classes that cause particles to interact with each other, causing the particles to approach one another but not get too close and to match velocity with each other.
The example is created in a single document class as follows
package
{
import flash.display.Sprite;
import flash.geom.Point;
import org.flintparticles.actions.*;
import org.flintparticles.counters.*;
import org.flintparticles.emitters.Emitter;
import org.flintparticles.initializers.*;
import org.flintparticles.renderers.*;
import org.flintparticles.zones.*;
public class Flocking extends Sprite
{
[Embed(source='assets/bird.swf', symbol='Bird')]
public var Bird:Class;
private var emitter:Emitter;
public function Flocking()
{
emitter = new Emitter();
emitter.counter = new Blast( 150 );
emitter.addInitializer( new ImageClass( Bird ) );
emitter.addInitializer( new ColorInit( 0xFFFF00FF, 0xFF00FFFF ) );
emitter.addInitializer( new Position( new RectangleZone( 10, 10, 680, 480 ) ) );
emitter.addInitializer( new Velocity( new DiscZone( new Point( 0, 0 ), 150, 100 ) ) );
emitter.addAction( new ApproachNeighbours( 100, 100 ) );
emitter.addAction( new MatchVelocity( 20, 200 ) );
emitter.addAction( new MinimumDistance( 10, 400 ) );
emitter.addAction( new SpeedLimit( 100, true ) );
emitter.addAction( new RotateToDirection() );
emitter.addAction( new BoundingBox( 0, 0, 700, 500 ) );
emitter.addAction( new SpeedLimit( 200 ) );
emitter.addAction( new Move() );
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
emitter.renderer = renderer;
addChild( renderer );
emitter.start( );
}
}
}
N.B. This example uses the embed meta-data tag as used by the Flex SDK. The Flash version, with the image embedded as a library asset, is available in the examples download.