Mutual Gravity

This example uses Mutual Gravity to attract the particles to each other. Each particle is attracted to every other particle by a gravitational force.

package
{
  import org.flintparticles.twoD.emitters.Emitter2D;
  import org.flintparticles.twoD.renderers.BitmapRenderer;

  import flash.display.Sprite;
  import flash.filters.BlurFilter;
  import flash.geom.Rectangle;

  [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var emitter:Emitter2D;
    
    public function Main()
    {
      emitter = new MutualG();

      var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 400, 400 ) );
      renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
      renderer.addEmitter( emitter );
      addChild( renderer );

      emitter.start( );
    }
  }
}
package
{
  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.displayObjects.Dot;
  import org.flintparticles.common.initializers.ColorInit;
  import org.flintparticles.common.initializers.SharedImage;
  import org.flintparticles.twoD.actions.BoundingBox;
  import org.flintparticles.twoD.actions.Move;
  import org.flintparticles.twoD.actions.MutualGravity;
  import org.flintparticles.twoD.actions.SpeedLimit;
  import org.flintparticles.twoD.emitters.Emitter2D;
  import org.flintparticles.twoD.initializers.Position;
  import org.flintparticles.twoD.zones.RectangleZone;

  public class MutualG extends Emitter2D
  {
    public function MutualG()
    {
      counter = new Blast( 40 );
      
      addInitializer( new SharedImage( new Dot( 2 ) ) );
      addInitializer( new ColorInit( 0xFFFF00FF, 0xFF00FFFF ) );
      addInitializer( new Position( new RectangleZone( 10, 10, 380, 380 ) ) );

      addAction( new MutualGravity( 10, 500, 3 ) );
      addAction( new BoundingBox( 0, 0, 400, 400 ) );
      addAction( new SpeedLimit( 150 ) );
      addAction( new Move() );
    }
  }
}
import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.Dot;
import org.flintparticles.common.initializers.*;
import org.flintparticles.twoD.actions.*;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.initializers.*;
import org.flintparticles.twoD.renderers.*;
import org.flintparticles.twoD.zones.*;  

var emitter:Emitter2D = new Emitter2D();

emitter.counter = new Blast( 40 );

emitter.addInitializer( new SharedImage( new Dot( 2 ) ) );
emitter.addInitializer( new ColorInit( 0xFFFF00FF, 0xFF00FFFF ) );
emitter.addInitializer( new Position( new RectangleZone( 10, 10, 380, 380 ) ) );

emitter.addAction( new MutualGravity( 10, 500, 3 ) );
emitter.addAction( new BoundingBox( 0, 0, 400, 400 ) );
emitter.addAction( new SpeedLimit( 150 ) );
emitter.addAction( new Move() );

var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 400, 400 ) );
renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
renderer.addEmitter( emitter );
addChild( renderer );

emitter.start( );
<?xml version="1.0" encoding="utf-8"?>
<s:Application
  xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:f="http://flintparticles.org/2009/flint2d"
  xmlns:filters="flash.filters.*"
  width="400" height="400"
  backgroundColor="#000000">
  
<f:BitmapRenderer id="renderer" width="400" height="400">
  <f:preFilters>
    <filters:BlurFilter blurX="2" blurY="2" quality="1"/>
  </f:preFilters>
  <f:emitters>
    <f:Emitter id="emitter" autoStart="true">
      <f:counter>
        <f:Blast startCount="40"/>
      </f:counter>
      <f:initializers>
        <f:Position>
          <f:RectangleZone left="10" right="390" top="10" bottom="390"/>
        </f:Position>
        <f:SharedImage>
          <f:Dot radius="2"/>
        </f:SharedImage>
        <f:ColorInit minColor="0xFFFF00FF" maxColor="0xFF00FFFF"/>
      </f:initializers>
      <f:actions>
        <f:Move/>
        <f:MutualGravity power="10" maxDistance="500" epsilon="3"/>
        <f:SpeedLimit limit="150"/>
        <f:BoundingBox left="0" right="400" top="0" bottom="400"/>
      </f:actions>
    </f:Emitter>
  </f:emitters>
</f:BitmapRenderer>
</s:Application>