Fire and Smoke

This project uses two emitters, one to create the fire and the other to create the smoke. The smoke is created from a number of circular particles at very low alpha which overlap to create the random smoke distribution. The fire is created from elliptical particles that are orientated so their pointy end points in the direction they’re traveling.

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

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

  [SWF(width='300', height='400', frameRate='60', backgroundColor='#000000')]
  
  

  public class Main extends Sprite
  {
    private var smoke:Emitter2D;
    private var fire:Emitter2D;
    
    public function Main()
    {
      smoke = new Smoke();
      smoke.x = 150;
      smoke.y = 380;
      smoke.start();
      
      fire = new Fire();
      fire.x = 150;
      fire.y = 380;
      fire.start();
      
      var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 300, 400 ) );
      renderer.addEmitter( smoke );
      renderer.addEmitter( fire );
      addChild( renderer );
    }
  }
}
package
{
  import org.flintparticles.common.actions.Age;
  import org.flintparticles.common.actions.ColorChange;
  import org.flintparticles.common.actions.ScaleImage;
  import org.flintparticles.common.counters.Steady;
  import org.flintparticles.common.initializers.Lifetime;
  import org.flintparticles.common.initializers.SharedImage;
  import org.flintparticles.twoD.actions.Accelerate;
  import org.flintparticles.twoD.actions.LinearDrag;
  import org.flintparticles.twoD.actions.Move;
  import org.flintparticles.twoD.actions.RotateToDirection;
  import org.flintparticles.twoD.emitters.Emitter2D;
  import org.flintparticles.twoD.initializers.Position;
  import org.flintparticles.twoD.initializers.Velocity;
  import org.flintparticles.twoD.zones.DiscSectorZone;
  import org.flintparticles.twoD.zones.DiscZone;

  import flash.geom.Point;

  public class Fire extends Emitter2D
  {
    public function Fire()
    {
      counter = new Steady( 60 );

      addInitializer( new Lifetime( 2, 3 ) );
      addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 20, 10, -Math.PI, 0 ) ) );
      addInitializer( new Position( new DiscZone( new Point( 0, 0 ), 3 ) ) );
      addInitializer( new SharedImage( new FireBlob() ) );

      addAction( new Age( ) );
      addAction( new Move( ) );
      addAction( new LinearDrag( 1 ) );
      addAction( new Accelerate( 0, -40 ) );
      addAction( new ColorChange( 0xFFFFCC00, 0x00CC0000 ) );
      addAction( new ScaleImage( 1, 1.5 ) );
      addAction( new RotateToDirection() );
    }
  }
}
package
{
  import org.flintparticles.common.actions.Age;
  import org.flintparticles.common.actions.Fade;
  import org.flintparticles.common.actions.ScaleImage;
  import org.flintparticles.common.counters.Steady;
  import org.flintparticles.common.displayObjects.RadialDot;
  import org.flintparticles.common.initializers.Lifetime;
  import org.flintparticles.common.initializers.SharedImage;
  import org.flintparticles.twoD.actions.LinearDrag;
  import org.flintparticles.twoD.actions.Move;
  import org.flintparticles.twoD.actions.RandomDrift;
  import org.flintparticles.twoD.emitters.Emitter2D;
  import org.flintparticles.twoD.initializers.Velocity;
  import org.flintparticles.twoD.zones.DiscSectorZone;

  import flash.geom.Point;

  public class Smoke extends Emitter2D
  {
    public function Smoke()
    {
      counter = new Steady( 10 );
      
      addInitializer( new Lifetime( 11, 12 ) );
      addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 40, 30, -4 * Math.PI / 7, -3 * Math.PI / 7 ) ) );
      addInitializer( new SharedImage( new RadialDot( 6 ) ) );
      
      addAction( new Age( ) );
      addAction( new Move( ) );
      addAction( new LinearDrag( 0.01 ) );
      addAction( new ScaleImage( 1, 15 ) );
      addAction( new Fade( 0.15, 0 ) );
      addAction( new RandomDrift( 15, 15 ) );
    }
  }
}
import org.flintparticles.common.actions.*;
import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.RadialDot;
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 smoke:Emitter2D = new Emitter2D();
smoke.counter = new Steady( 10 );

smoke.addInitializer( new Lifetime( 11, 12 ) );
smoke.addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 40, 30, -4 * Math.PI / 7, -3 * Math.PI / 7 ) ) );
smoke.addInitializer( new SharedImage( new RadialDot( 6 ) ) );
  
smoke.addAction( new Age( ) );
smoke.addAction( new Move( ) );
smoke.addAction( new LinearDrag( 0.01 ) );
smoke.addAction( new ScaleImage( 1, 15 ) );
smoke.addAction( new Fade( 0.15, 0 ) );
smoke.addAction( new RandomDrift( 15, 15 ) );

smoke.x = 150;
smoke.y = 380;
smoke.start( );

var fire:Emitter2D = new Emitter2D();
fire.counter = new Steady( 60 );

fire.addInitializer( new Lifetime( 2, 3 ) );
fire.addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 20, 10, -Math.PI, 0 ) ) );
fire.addInitializer( new Position( new DiscZone( new Point( 0, 0 ), 3 ) ) );
fire.addInitializer( new SharedImage( new FireBlob() ) );

fire.addAction( new Age( ) );
fire.addAction( new Move( ) );
fire.addAction( new LinearDrag( 1 ) );
fire.addAction( new Accelerate( 0, -40 ) );
fire.addAction( new ColorChange( 0xFFFFCC00, 0x00CC0000 ) );
fire.addAction( new ScaleImage( 1, 1.5 ) );
fire.addAction( new RotateToDirection() );

fire.x = 150;
fire.y = 380;
fire.start( );

var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( 0, 0, 300, 400 ) );
renderer.addEmitter( fire );
renderer.addEmitter( smoke );
addChild( renderer );
<?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"
  width="300" height="400"
  backgroundColor="#000000">
  
<f:BitmapRenderer id="renderer" width="300" height="400">
  <f:emitters>
    <f:Emitter id="smoke" autoStart="true" x="150" y="380">
      <f:counter>
        <f:Steady rate="10"/>
      </f:counter>
      <f:initializers>
        <f:Lifetime minLifetime="11" maxLifetime="12"/>
        <f:Velocity>
          <f:DiscSectorZone centerX="0" centerY="0" innerRadius="30" outerRadius="40" minAngle="{-4 * Math.PI / 7}" maxAngle="{-3 * Math.PI / 7}"/>
        </f:Velocity>
        <f:SharedImage>
          <f:RadialDot radius="6"/>
        </f:SharedImage>
      </f:initializers>
      <f:actions>
        <f:Move/>
        <f:Age/>
        <f:LinearDrag drag="0.04"/>
        <f:Fade startAlpha="0.15" endAlpha="0"/>
        <f:ScaleImage startScale="1" endScale="15"/>
        <f:RandomDrift driftX="15" driftY="15"/>
      </f:actions>
    </f:Emitter>
    <f:Emitter id="fire" autoStart="true" x="150" y="380">
      <f:counter>
        <f:Steady rate="60"/>
      </f:counter>
      <f:initializers>
        <f:Lifetime minLifetime="2" maxLifetime="3"/>
        <f:Position>
          <f:DiscZone centerX="0" centerY="0" outerRadius="3"/>
        </f:Position>
        <f:Velocity>
          <f:DiscSectorZone centerX="0" centerY="0" innerRadius="10" outerRadius="20" minAngle="{-Math.PI}" maxAngle="0"/>
        </f:Velocity>
        <f:SharedImage image="{new FireBlob()}"/>
      </f:initializers>
      <f:actions>
        <f:Move/>
        <f:RotateToDirection/>
        <f:Age/>
        <f:LinearDrag drag="1"/>
        <f:Accelerate x="0" y="-40"/>
        <f:ColorChange startColor="0xFFFFCC00" endColor="0x00CC0000"/>
        <f:ScaleImage startScale="1" endScale="1.5"/>
      </f:actions>
    </f:Emitter>
  </f:emitters>
</f:BitmapRenderer>
</s:Application>