Fork me on GitHub

Gravity Wells

Flash required: You need version 10 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.

This example uses a number of gravity wells and 4000 particles. The gravity wells behave as static points of gravitational attraction. All the particles are drawn towards the five gravity wells, producing the complex pattern of motion seen above.

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

  import flash.display.Sprite;
  import flash.filters.BlurFilter;
  import flash.filters.ColorMatrixFilter;
  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 GravityWells();

      var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 400, 400 ) );
      renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
      renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.99,0 ] ) );
      renderer.addEmitter( emitter );
      addChild( renderer );
      
      emitter.start();
    }
  }
}
package
{
  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ColorInit;
  import org.flintparticles.twoD.actions.GravityWell;
  import org.flintparticles.twoD.actions.Move;
  import org.flintparticles.twoD.emitters.Emitter2D;
  import org.flintparticles.twoD.initializers.Position;
  import org.flintparticles.twoD.zones.DiscZone;

  import flash.geom.Point;

  public class GravityWells extends Emitter2D
  {
    public function GravityWells()
    {
      counter = new Blast( 10000 );
      
      addInitializer( new ColorInit( 0xFFFF00FF, 0xFF00FFFF ) );
      addInitializer( new Position( new DiscZone( new Point( 200, 200 ), 200 ) ) );

      addAction( new Move() );
      addAction( new GravityWell( 25, 200, 200 ) );
      addAction( new GravityWell( 25, 75, 75 ) );
      addAction( new GravityWell( 25, 325, 325 ) );
      addAction( new GravityWell( 25, 75, 325 ) );
      addAction( new GravityWell( 25, 325, 75 ) );
    }
  }
}
import org.flintparticles.common.counters.*;
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( 10000 );

emitter.addInitializer( new ColorInit( 0xFFFF00FF, 0xFF00FFFF ) );
emitter.addInitializer( new Position( new DiscZone( new Point( 200, 200 ), 200 ) ) );

emitter.addAction( new Move() );
emitter.addAction( new GravityWell( 25, 200, 200 ) );
emitter.addAction( new GravityWell( 25, 75, 75 ) );
emitter.addAction( new GravityWell( 25, 325, 325 ) );
emitter.addAction( new GravityWell( 25, 75, 325 ) );
emitter.addAction( new GravityWell( 25, 325, 75 ) );

var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 400, 400 ) );
renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.99,0 ] ) );
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:PixelRenderer id="renderer" width="400" height="400">
  <f:preFilters>
    <filters:BlurFilter blurX="2" blurY="2" quality="1"/>
    <filters:ColorMatrixFilter matrix="{[ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.99,0 ]}"/>
  </f:preFilters>
  <f:emitters>
    <f:Emitter id="emitter" autoStart="true">
      <f:counter>
        <f:Blast startCount="10000"/>
      </f:counter>
      <f:initializers>
        <f:Position>
          <f:DiscZone centerX="200" centerY="200" outerRadius="200"/>
        </f:Position>
        <f:ColorInit minColor="0xFFFF00FF" maxColor="0xFF00FFFF"/>
      </f:initializers>
      <f:actions>
        <f:Move/>
        <f:GravityWell power="25" x="200" y="200"/>
        <f:GravityWell power="25" x="75" y="75"/>
        <f:GravityWell power="25" x="325" y="325"/>
        <f:GravityWell power="25" x="75" y="325"/>
        <f:GravityWell power="25" x="325" y="75"/>
      </f:actions>
    </f:Emitter>
  </f:emitters>
</f:PixelRenderer>
</s:Application>