Flint Particles: Snowfall

# Snowfall

The snow effect from the tutorial overlaid on an image.

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

      import flash.display.Bitmap;
      import flash.display.Sprite;

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

      public class Main extends Sprite
      {
        private var emitter:Emitter2D;

        public function Main()
        {
          emitter = new Snowfall();

          addChild( new Bitmap( new SnowBackground( 600, 400 ) ) );

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

          addChild( new Bitmap( new SnowForeground( 600, 400 ) ) );

          emitter.start();
          emitter.runAhead( 10 );
        }
      }
    }

    package
    {
      import org.flintparticles.common.counters.Steady;
      import org.flintparticles.common.displayObjects.RadialDot;
      import org.flintparticles.common.initializers.ImageClass;
      import org.flintparticles.common.initializers.ScaleImageInit;
      import org.flintparticles.twoD.actions.DeathZone;
      import org.flintparticles.twoD.actions.Move;
      import org.flintparticles.twoD.actions.RandomDrift;
      import org.flintparticles.twoD.emitters.Emitter2D;
      import org.flintparticles.twoD.initializers.Position;
      import org.flintparticles.twoD.initializers.Velocity;
      import org.flintparticles.twoD.zones.LineZone;
      import org.flintparticles.twoD.zones.PointZone;
      import org.flintparticles.twoD.zones.RectangleZone;

      import flash.geom.Point;

      public class Snowfall extends Emitter2D
      {
        public function Snowfall()
        {
          counter = new Steady( 150 );

          addInitializer( new ImageClass( RadialDot, [2] ) );
          addInitializer( new Position( new LineZone( new Point( -5, -5 ), new Point( 605, -5 ) ) ) );
          addInitializer( new Velocity( new PointZone( new Point( 0, 65 ) ) ) );
          addInitializer( new ScaleImageInit( 0.75, 2 ) );

          addAction( new Move() );
          addAction( new DeathZone( new RectangleZone( -10, -10, 620, 420 ), true ) );
          addAction( new RandomDrift( 20, 20 ) );
        }
      }
    }

    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.*;

    addChild( new SnowBackground() );

    var emitter:Emitter2D = new Emitter2D();

    emitter.counter = new Steady( 150 );

    emitter.addInitializer( new ImageClass( RadialDot, [2] ) );
    emitter.addInitializer( new Position( new LineZone( new Point( -5, -5 ), new Point( 605, -5 ) ) ) );
    emitter.addInitializer( new Velocity( new PointZone( new Point( 0, 65 ) ) ) );
    emitter.addInitializer( new ScaleImageInit( 0.75, 2 ) );

    emitter.addAction( new Move() );
    emitter.addAction( new DeathZone( new RectangleZone( -10, -10, 620, 420 ), true ) );
    emitter.addAction( new RandomDrift( 20, 20 ) );

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

    emitter.start();
    emitter.runAhead( 10 );

    addChild( new SnowForeground() );

    <?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="600" height="400">

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

    <s:BitmapImage source="{new SnowBackground( 600, 400 )}" width="600" height="400"/>
    <f:DisplayObjectRenderer id="renderer" width="600" height="400">
      <f:emitters>
        <f:Emitter id="emitter" autoStart="true" runAheadTime="10">
          <f:counter>
            <f:Steady rate="150"/>
          </f:counter>
          <f:initializers>
            <f:Position>
              <f:LineZone startX="-5" startY="-5" endX="605" endY="-5"/>
            </f:Position>
            <f:Velocity>
              <f:PointZone x="0" y="65"/>
            </f:Velocity>
            <f:ImageClass imageClass="{RadialDot}" parameters="{[2]}"/>
            <f:ScaleImageInit minScale="0.75" maxScale="2"/>
          </f:initializers>
          <f:actions>
            <f:Move/>
            <f:DeathZone zoneIsSafe="true">
              <f:RectangleZone left="-10" right="620" top="-10" bottom="420"/>
            </f:DeathZone>
            <f:RandomDrift driftX="20" driftY="20"/>
          </f:actions>
        </f:Emitter>
      </f:emitters>
    </f:DisplayObjectRenderer>
    <s:BitmapImage source="{new SnowForeground( 600, 400 )}" width="600" height="400"/>
    </s:Application>