Fork me on GitHub

Brownian Motion

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 simulates Brownian Motion. It demonstrates Flint’s built-in collision handling between particles.

The example also includes a custom action created to show and hide the air particles.

package
{
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.renderers.DisplayObjectRenderer;
  import org.flintparticles.threeD.renderers.controllers.OrbitCamera;

  import flash.display.Sprite;
  import flash.geom.Vector3D;

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

      var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
      renderer.x = 200;
      renderer.y = 200;
      renderer.addEmitter( emitter );
      addChild( renderer );
      
      renderer.camera.position = new Vector3D( 0, 0, -400 );
      renderer.camera.target = new Vector3D( 0, 0, 0 );
      renderer.camera.projectionDistance = 400;
      orbitter = new OrbitCamera( stage, renderer.camera );
      orbitter.start();

      emitter.start();
    }
  }
}
package
{
  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.displayObjects.Dot;
  import org.flintparticles.common.initializers.ChooseInitializer;
  import org.flintparticles.common.initializers.CollisionRadiusInit;
  import org.flintparticles.common.initializers.ColorInit;
  import org.flintparticles.common.initializers.ImageClass;
  import org.flintparticles.common.initializers.InitializerGroup;
  import org.flintparticles.common.initializers.MassInit;
  import org.flintparticles.threeD.actions.BoundingBox;
  import org.flintparticles.threeD.actions.Collide;
  import org.flintparticles.threeD.actions.Move;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.initializers.Position;
  import org.flintparticles.threeD.initializers.Velocity;
  import org.flintparticles.threeD.zones.BoxZone;
  import org.flintparticles.threeD.zones.SphereZone;

  import flash.display.DisplayObject;
  import flash.geom.Vector3D;

  public class BrownianMotion extends Emitter3D
  {
    public function BrownianMotion( stage:DisplayObject )
    {
      counter = new Blast( 400 );
      
      var air:InitializerGroup = new InitializerGroup();
      air.addInitializer( new ImageClass( Dot, [2] ) );
      air.addInitializer( new ColorInit( 0xFF666666, 0xFF666666 ) );
      air.addInitializer( new MassInit( 1 ) );
      air.addInitializer( new CollisionRadiusInit( 2 ) );
      
      var smoke:InitializerGroup = new InitializerGroup();
      smoke.addInitializer( new ImageClass( Dot, [10] ) );
      smoke.addInitializer( new ColorInit( 0xFFFFFFFF, 0xFFFFFFFF ) );
      smoke.addInitializer( new MassInit( 5 ) );
      smoke.addInitializer( new CollisionRadiusInit( 10 ) );
      
      addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
      addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
      
      addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );
      
      addAction( new Move() );
      addAction( new Collide( 1 ) );
      addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
      addAction( new ShowAirAction( stage ) );
    }
  }
}
package
{
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}
import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.Dot;
import org.flintparticles.common.initializers.*;
import org.flintparticles.threeD.actions.*;
import org.flintparticles.threeD.emitters.Emitter3D;
import org.flintparticles.threeD.initializers.*;
import org.flintparticles.threeD.renderers.*;
import org.flintparticles.threeD.renderers.controllers.OrbitCamera;
import org.flintparticles.threeD.zones.*;  

var emitter:Emitter3D = new Emitter3D();
emitter.counter = new Blast( 400 );

var air:InitializerGroup = new InitializerGroup();
air.addInitializer( new ImageClass( Dot, [2] ) );
air.addInitializer( new ColorInit( 0xFF666666, 0xFF666666 ) );
air.addInitializer( new MassInit( 1 ) );
air.addInitializer( new CollisionRadiusInit( 2 ) );

var smoke:InitializerGroup = new InitializerGroup();
smoke.addInitializer( new ImageClass( Dot, [10] ) );
smoke.addInitializer( new ColorInit( 0xFFFFFFFF, 0xFFFFFFFF ) );
smoke.addInitializer( new MassInit( 5 ) );
smoke.addInitializer( new CollisionRadiusInit( 10 ) );

emitter.addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
emitter.addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
emitter.addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );

emitter.addAction( new Move() );
emitter.addAction( new Collide( 1 ) );
emitter.addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
emitter.addAction( new ShowAirAction( stage ) );

var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
renderer.x = 200;
renderer.y = 200;
renderer.addEmitter( emitter );
addChild( renderer );

renderer.camera.position = new Vector3D( 0, 0, -400 );
renderer.camera.target = new Vector3D( 0, 0, 0 );
renderer.camera.projectionDistance = 400;
var orbitter:OrbitCamera = new OrbitCamera( stage, renderer.camera );
orbitter.start();

emitter.start();
package
{
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}
<?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/flint3d"
  xmlns:geom="flash.geom.*"
  xmlns:local="*"
  width="500" height="500"
  backgroundColor="#000000">

<fx:Script>
  <![CDATA[
    import org.flintparticles.common.displayObjects.Dot;
  ]]>
</fx:Script>

<f:DisplayObjectRenderer id="renderer" width="500" height="500">
  <f:camera>
    <f:Camera projectionDistance="400">
      <f:position>
        <geom:Vector3D x="0" y="0" z="-400"/>
      </f:position>
    </f:Camera>
  </f:camera>
  <f:emitters>
    <f:Emitter id="emitter" autoStart="true">
      <f:counter>
        <f:Blast startCount="400"/>
      </f:counter>
      <f:initializers>
        <f:Position>
          <f:BoxZone width="280" height="280" depth="280"/>
        </f:Position>
        <f:Velocity>
          <f:SphereZone innerRadius="100" outerRadius="150"/>
        </f:Velocity>
        <f:ChooseInitializer weights="1,30">
          <f:InitializerGroup>
            <f:ImageClass imageClass="{Dot}" parameters="10"/>
            <f:CollisionRadiusInit radius="10"/>
            <f:MassInit mass="5"/>
            <f:ColorInit minColor="0xFFFFFFFF" maxColor="0xFFFFFFFF"/>
          </f:InitializerGroup>
          <f:InitializerGroup>
            <f:ImageClass imageClass="{Dot}" parameters="2"/>
            <f:CollisionRadiusInit radius="2"/>
            <f:MassInit mass="1"/>
            <f:ColorInit minColor="0xFF666666" maxColor="0xFF666666"/>
          </f:InitializerGroup>            
        </f:ChooseInitializer>
      </f:initializers>
      <f:actions>
        <f:Move/>
        <f:Collide bounce="1"/>
        <f:BoundingBox minX="-150" maxX="150" minY="-150" maxY="150" minZ="-150" maxZ="150"/>
        <local:ShowAirAction/>
      </f:actions>
    </f:Emitter>
  </f:emitters>
</f:DisplayObjectRenderer>
</s:Application>
package
{
  import flash.display.DisplayObject;
  import flash.events.Event;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;
  
  import mx.core.IMXMLObject;
  
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;  

  

  public class ShowAirAction extends ActionBase implements IMXMLObject
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction()
    {
      _isDown = false;
    }
    
    public function initialized( document:Object, id:String ):void
    {
      if( document.stage )
      {
        setStage( document.stage );
      }
      else
      {
        DisplayObject( document ).addEventListener( Event.ADDED_TO_STAGE, addedToStage );
      }
    }
      
    private function addedToStage( ev:Event ):void
    {
      setStage( ev.target.stage );
    }  
    
    private function setStage( stage:DisplayObject ):void
    {
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}
package
{
  import away3d.containers.ObjectContainer3D;
  import away3d.containers.View3D;

  import org.flintparticles.integration.away3d.v4.A3D4Renderer;
  import org.flintparticles.threeD.emitters.Emitter3D;

  import flash.display.Sprite;
  import flash.events.Event;

  [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var emitter:Emitter3D;
    private var view:View3D;
    private var renderer:A3D4Renderer;
    
    public function Main()
    {
      emitter = new BrownianMotion( stage );

      view = new View3D();
      view.width = 400;
      view.height = 400;
      addChild( view );
      
      var particleContainer:ObjectContainer3D = new ObjectContainer3D();
      view.scene.addChild( particleContainer );
      particleContainer.z = -200;
      
      renderer = new A3D4Renderer( particleContainer );
      renderer.addEmitter( emitter );

      emitter.start();
      
      addEventListener( Event.ENTER_FRAME, render, false, 0, true );
    }
    
    private function render( ev:Event ):void
    {
      // render the view
      view.render();
    }
  }
}
package
{
  import away3d.materials.ColorMaterial;
  import away3d.primitives.Sphere;

  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ChooseInitializer;
  import org.flintparticles.common.initializers.CollisionRadiusInit;
  import org.flintparticles.common.initializers.InitializerGroup;
  import org.flintparticles.common.initializers.MassInit;
  import org.flintparticles.integration.away3d.v4.initializers.A3D4CloneObject;
  import org.flintparticles.threeD.actions.BoundingBox;
  import org.flintparticles.threeD.actions.Collide;
  import org.flintparticles.threeD.actions.Move;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.initializers.Position;
  import org.flintparticles.threeD.initializers.Velocity;
  import org.flintparticles.threeD.zones.BoxZone;
  import org.flintparticles.threeD.zones.SphereZone;

  import flash.display.DisplayObject;
  import flash.geom.Vector3D;

  public class BrownianMotion extends Emitter3D
  {
    public function BrownianMotion( stage:DisplayObject )
    {
      counter = new Blast( 400 );
      
      var air:InitializerGroup = new InitializerGroup();
      var airImage:Sphere = new Sphere( new ColorMaterial( 0x666666, 1 ), 2, 6, 6 );
      air.addInitializer( new A3D4CloneObject( airImage ) );
      air.addInitializer( new MassInit( 1 ) );
      air.addInitializer( new CollisionRadiusInit( 2 ) );
      
      var smoke:InitializerGroup = new InitializerGroup();
      var smokeImage:Sphere = new Sphere( new ColorMaterial( 0xFFFFFF, 1 ), 10, 10, 10 );
      smoke.addInitializer( new A3D4CloneObject( smokeImage ) );
      smoke.addInitializer( new MassInit( 5 ) );
      smoke.addInitializer( new CollisionRadiusInit( 10 ) );
      
      addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
      addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
      
      addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );
      
      addAction( new Move() );
      addAction( new Collide( 1 ) );
      addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
      addAction( new ShowAirAction( stage ) );
    }
  }
}
package
{
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}
package
{
  import flare.basic.Scene3D;
  import flare.basic.Viewer3D;
  import flare.core.Pivot3D;

  import org.flintparticles.integration.flare3d.F3DRenderer;
  import org.flintparticles.threeD.emitters.Emitter3D;

  import flash.display.Sprite;
  import flash.geom.Vector3D;

  [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var emitter:Emitter3D;
    private var scene:Scene3D;
    private var renderer:F3DRenderer;
    
    public function Main()
    {
      scene = new Viewer3D( this );
      scene.clearColor = new Vector3D( 0, 0, 0 );
      scene.camera.fieldOfView = 40;
      
      var particleContainer:Pivot3D = new Pivot3D();
      scene.addChild( particleContainer );
      particleContainer.z = 500;
      
      emitter = new BrownianMotion( stage );
      renderer = new F3DRenderer( particleContainer );
      renderer.addEmitter( emitter );

      emitter.start();
    }
  }
}
package
{
  import flare.materials.Shader3D;
  import flare.materials.filters.ColorFilter;
  import flare.primitives.Sphere;

  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ChooseInitializer;
  import org.flintparticles.common.initializers.CollisionRadiusInit;
  import org.flintparticles.common.initializers.ColorInit;
  import org.flintparticles.common.initializers.InitializerGroup;
  import org.flintparticles.common.initializers.MassInit;
  import org.flintparticles.integration.flare3d.initializers.F3DCloneObject;
  import org.flintparticles.threeD.actions.BoundingBox;
  import org.flintparticles.threeD.actions.Collide;
  import org.flintparticles.threeD.actions.Move;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.initializers.Position;
  import org.flintparticles.threeD.initializers.Velocity;
  import org.flintparticles.threeD.zones.BoxZone;
  import org.flintparticles.threeD.zones.SphereZone;

  import flash.display.DisplayObject;
  import flash.geom.Vector3D;

  public class BrownianMotion extends Emitter3D
  {
    public function BrownianMotion( stage:DisplayObject )
    {
      counter = new Blast( 400 );

      var air:InitializerGroup = new InitializerGroup();
      var airMaterial:Shader3D = new Shader3D( 'airShader', [new ColorFilter( 0x666666 )], false );
      airMaterial.build();
      var airImage:Sphere = new Sphere( 'sphere', 2, 12, airMaterial );
      air.addInitializer( new F3DCloneObject( airImage ) );
      air.addInitializer( new MassInit( 1 ) );
      air.addInitializer( new CollisionRadiusInit( 2 ) );
      air.addInitializer( new ColorInit( 0xFF666666, 0xFF666666 ) );
      
      var smoke:InitializerGroup = new InitializerGroup();
      var smokeMaterial:Shader3D = new Shader3D( 'smokeShader', [new ColorFilter( 0xFFFFFF )], false );
      smokeMaterial.build();
      var smokeImage:Sphere = new Sphere( 'sphere', 10, 20, smokeMaterial );
      smoke.addInitializer( new F3DCloneObject( smokeImage ) );
      smoke.addInitializer( new MassInit( 5 ) );
      smoke.addInitializer( new CollisionRadiusInit( 10 ) );
      
      addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
      addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
      
      addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );

      addAction( new Move() );
      addAction( new Collide( 1 ) );
      addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
      addAction( new ShowAirAction( stage ) );
    }
  }
}
package
{
  import flare.core.Pivot3D;

  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          //particle.color = 0;
          Pivot3D( particle.image ).hide();
        }
        else
        {
          //particle.color = 0xFF666666;
          Pivot3D( particle.image ).show();
        }
      }
    }
  }
}
package
{
  import alternativa.engine3d.core.Camera3D;
  import alternativa.engine3d.core.Object3D;
  import alternativa.engine3d.core.Resource;
  import alternativa.engine3d.core.View;

  import org.flintparticles.integration.alternativa3d.Alt3DRenderer;
  import org.flintparticles.threeD.emitters.Emitter3D;

  import flash.display.Sprite;
  import flash.display.Stage3D;
  import flash.events.Event;

  [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var emitter : Emitter3D;
    private var particleContainer : Object3D;
    private var camera : Camera3D;
    private var stage3D : Stage3D;
    private var renderer : Alt3DRenderer;

    public function Main()
    {
      camera = new Camera3D( 0.1, 10000 );
      camera.view = new View( stage.stageWidth, stage.stageHeight );
      camera.view.backgroundColor = 0x000000;
      camera.view.hideLogo();
      addChild( camera.view );
      addChild( camera.diagram );
      
      camera.rotationX = 0;
      camera.y = 0;
      camera.z = -360;

      stage3D = stage.stage3Ds[0];
      stage3D.addEventListener( Event.CONTEXT3D_CREATE, onContextCreate );
      stage3D.requestContext3D();
    }

    private function onContextCreate( event : Event ) : void
    {
      particleContainer = new Object3D();
      particleContainer.addChild( camera );
      renderer = new Alt3DRenderer( particleContainer );
      
      emitter = new BrownianMotion( stage );
      renderer.addEmitter( emitter );

      emitter.start();

      addEventListener( Event.ENTER_FRAME, render, false, 0, true );
    }

    private function render( ev : Event ) : void
    {
      // render the view
      camera.view.width = stage.stageWidth;
      camera.view.height = stage.stageHeight;
      camera.render( stage3D );
      for each ( var resource:Resource in particleContainer.getResources( true ) )
      {
        resource.upload( stage3D.context3D );
      }
    }
  }
}
package
{
  import alternativa.engine3d.materials.FillMaterial;
  import alternativa.engine3d.primitives.GeoSphere;

  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ChooseInitializer;
  import org.flintparticles.common.initializers.CollisionRadiusInit;
  import org.flintparticles.common.initializers.InitializerGroup;
  import org.flintparticles.common.initializers.MassInit;
  import org.flintparticles.integration.alternativa3d.initializers.Alt3DCloneObject;
  import org.flintparticles.threeD.actions.BoundingBox;
  import org.flintparticles.threeD.actions.Collide;
  import org.flintparticles.threeD.actions.Move;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.initializers.Position;
  import org.flintparticles.threeD.initializers.Velocity;
  import org.flintparticles.threeD.zones.BoxZone;
  import org.flintparticles.threeD.zones.SphereZone;

  import flash.display.DisplayObject;
  import flash.geom.Vector3D;

  public class BrownianMotion extends Emitter3D
  {
    public function BrownianMotion( stage:DisplayObject )
    {
      counter = new Blast( 400 );
      
      var air:InitializerGroup = new InitializerGroup();
      var airImage:GeoSphere = new GeoSphere( 2, 6, false, new FillMaterial( 0x666666, 1 ) );
      air.addInitializer( new Alt3DCloneObject( airImage ) );
      air.addInitializer( new MassInit( 1 ) );
      air.addInitializer( new CollisionRadiusInit( 2 ) );
      
      var smoke:InitializerGroup = new InitializerGroup();
      var smokeImage:GeoSphere = new GeoSphere( 10, 10, false, new FillMaterial( 0xFFFFFF, 1 ) );
      smoke.addInitializer( new Alt3DCloneObject( smokeImage ) );
      smoke.addInitializer( new MassInit( 5 ) );
      smoke.addInitializer( new CollisionRadiusInit( 10 ) );
      
      addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
      addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
      
      addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );
      
      addAction( new Move() );
      addAction( new Collide( 1 ) );
      addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
      addAction( new ShowAirAction( stage ) );
    }
  }
}
package
{
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}
package
{
  import away3d.containers.View3D;

  import org.flintparticles.integration.away3d.v3.A3D3Renderer;
  import org.flintparticles.threeD.emitters.Emitter3D;

  import flash.display.Sprite;
  import flash.events.Event;

  [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var emitter:Emitter3D;
    private var view:View3D;
    private var renderer:A3D3Renderer;
    
    public function Main()
    {
      emitter = new BrownianMotion( stage );

      view = new View3D({x:200,y:200});
      addChild(view);
      renderer = new A3D3Renderer( view.scene );
      renderer.addEmitter( emitter );

      emitter.start();
      
      addEventListener( Event.ENTER_FRAME, render, false, 0, true );
    }
    
    private function render( ev:Event ):void
    {
      // render the view
      view.render();
    }
  }
}
package
{
  import away3d.materials.ColorMaterial;
  import away3d.primitives.Sphere;

  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ChooseInitializer;
  import org.flintparticles.common.initializers.CollisionRadiusInit;
  import org.flintparticles.common.initializers.InitializerGroup;
  import org.flintparticles.common.initializers.MassInit;
  import org.flintparticles.integration.away3d.v3.initializers.A3D3ApplyMaterial;
  import org.flintparticles.integration.away3d.v3.initializers.A3D3ObjectClass;
  import org.flintparticles.threeD.actions.BoundingBox;
  import org.flintparticles.threeD.actions.Collide;
  import org.flintparticles.threeD.actions.Move;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.initializers.Position;
  import org.flintparticles.threeD.initializers.Velocity;
  import org.flintparticles.threeD.zones.BoxZone;
  import org.flintparticles.threeD.zones.SphereZone;

  import flash.display.DisplayObject;
  import flash.geom.Vector3D;

  public class BrownianMotion extends Emitter3D
  {
    public function BrownianMotion( stage:DisplayObject )
    {
      counter = new Blast( 400 );
      
      var air:InitializerGroup = new InitializerGroup();
      air.addInitializer( new A3D3ObjectClass( Sphere, [ { radius:2, segmentsW:4, segmentsH:4 } ] ) );
      air.addInitializer( new A3D3ApplyMaterial( ColorMaterial, 0x666666, 1 ) );
      air.addInitializer( new MassInit( 1 ) );
      air.addInitializer( new CollisionRadiusInit( 2 ) );
      
      var smoke:InitializerGroup = new InitializerGroup();
      smoke.addInitializer( new A3D3ObjectClass( Sphere, [ { radius:10, segmentsW:6, segmentsH:6 } ] ) );
      smoke.addInitializer( new A3D3ApplyMaterial( ColorMaterial, 0xFFFFFF, 1 ) );
      smoke.addInitializer( new MassInit( 5 ) );
      smoke.addInitializer( new CollisionRadiusInit( 10 ) );
      
      addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
      addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
      
      addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );
      
      addAction( new Move() );
      addAction( new Collide( 1 ) );
      addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
      addAction( new ShowAirAction( stage ) );
    }
  }
}
package
{
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}
package
{
  import org.flintparticles.integration.papervision3d.PV3DParticleRenderer;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.papervision3d.cameras.Camera3D;
  import org.papervision3d.core.geom.Particles;
  import org.papervision3d.render.BasicRenderEngine;
  import org.papervision3d.scenes.Scene3D;
  import org.papervision3d.view.Viewport3D;

  import flash.display.Sprite;
  import flash.events.Event;

  [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var viewport:Viewport3D;
    private var emitter:Emitter3D;
    private var pv3dRenderer:BasicRenderEngine;
    private var flintRenderer:PV3DParticleRenderer;
    private var scene:Scene3D;
    private var camera:Camera3D;

    public function Main()
    {
      viewport = new Viewport3D( 400, 400 );
      addChild( viewport );
      
      pv3dRenderer = new BasicRenderEngine();
      scene = new Scene3D();
      camera = new Camera3D();
      camera.z = -400;
      
      var particles:Particles = new Particles();
      scene.addChild( particles );
      
      emitter = new BrownianMotion( stage );

      flintRenderer = new PV3DParticleRenderer( particles );
      flintRenderer.addEmitter( emitter );
      emitter.start();
      
      addEventListener( Event.ENTER_FRAME, render );
    }
    
    private function render( ev:Event ):void
    {
      // render the view
      pv3dRenderer.renderScene( scene, camera, viewport);
    }
  }
}
package
{
  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ChooseInitializer;
  import org.flintparticles.common.initializers.CollisionRadiusInit;
  import org.flintparticles.common.initializers.ColorInit;
  import org.flintparticles.common.initializers.InitializerGroup;
  import org.flintparticles.common.initializers.MassInit;
  import org.flintparticles.integration.papervision3d.initializers.PV3DApplyMaterial;
  import org.flintparticles.integration.papervision3d.initializers.PV3DObjectClass;
  import org.flintparticles.threeD.actions.BoundingBox;
  import org.flintparticles.threeD.actions.Collide;
  import org.flintparticles.threeD.actions.Move;
  import org.flintparticles.threeD.emitters.Emitter3D;
  import org.flintparticles.threeD.initializers.Position;
  import org.flintparticles.threeD.initializers.Velocity;
  import org.flintparticles.threeD.zones.BoxZone;
  import org.flintparticles.threeD.zones.SphereZone;
  import org.papervision3d.core.geom.renderables.Particle;
  import org.papervision3d.materials.special.ParticleMaterial;

  import flash.display.DisplayObject;
  import flash.geom.Vector3D;

  public class BrownianMotion extends Emitter3D
  {
    public function BrownianMotion( stage:DisplayObject )
    {
      counter = new Blast( 400 );
      
      var air:InitializerGroup = new InitializerGroup();
      air.addInitializer( new PV3DObjectClass( Particle, null, 4 ) );
      air.addInitializer( new ColorInit( 0xFF666666, 0xFF666666 ) );
      air.addInitializer( new MassInit( 1 ) );
      air.addInitializer( new CollisionRadiusInit( 2 ) );
      air.addInitializer( new PV3DApplyMaterial( ParticleMaterial, 0x666666, 1, ParticleMaterial.SHAPE_CIRCLE ) );
      
      var smoke:InitializerGroup = new InitializerGroup();
      smoke.addInitializer( new PV3DObjectClass( Particle, null, 20 ) );
      smoke.addInitializer( new ColorInit( 0xFFFFFFFF, 0xFFFFFFFF ) );
      smoke.addInitializer( new MassInit( 5 ) );
      smoke.addInitializer( new CollisionRadiusInit( 10 ) );
      smoke.addInitializer( new PV3DApplyMaterial( ParticleMaterial, 0xFFFFFF, 1, ParticleMaterial.SHAPE_CIRCLE ) );
      
      addInitializer( new Position( new BoxZone( 280, 280, 280, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
      addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 0 ), 150, 100 ) ) );
      
      addInitializer( new ChooseInitializer( [ air, smoke ], [ 30, 1 ] ) );
      
      addAction( new Move() );
      addAction( new Collide( 1 ) );
      addAction( new BoundingBox( -150, 150, -150, 150, -150, 150, 1 ) );
      addAction( new ShowAirAction( stage ) );
    }
  }
}
package
{
  import org.flintparticles.common.actions.ActionBase;
  import org.flintparticles.common.emitters.Emitter;
  import org.flintparticles.common.particles.Particle;

  import flash.display.DisplayObject;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  

  public class ShowAirAction extends ActionBase
  {
    private var _isDown:Boolean;
    
    
    public function ShowAirAction( stage:DisplayObject )
    {
      _isDown = false;
      stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
      stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
    }
    
    private function keyDownListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = true;
      }
    }
    private function keyUpListener( ev:KeyboardEvent ):void
    {
      if( ev.keyCode == Keyboard.SHIFT )
      {
        _isDown = false;
      }
    }

    
    override public function update( emitter:Emitter, particle:Particle, time:Number ):void
    {
      if( particle.mass == 1 )
      {
        if( _isDown )
        {
          particle.color = 0;
        }
        else
        {
          particle.color = 0xFF666666;
        }
      }
    }
  }
}