Fork me on GitHub

Grass

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 line renderer to draw the grass. The grass will look different every time. I have deliberately made this draw slowly so the effect can be seen. It could be rendered much more rapidly by adjusting the velocity, acceleration and lifetime. The grass could also be draw instantaneously as a static image by using the runAhead method of the emitter to jump straight to the end state of the effect.

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

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

  [SWF(width='500', height='500', frameRate='60', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    private var emitter:Emitter2D;
    
    public function Main()
    {
      emitter = new Grass();
      emitter.x = 250;
      emitter.y = 450;
      
      var renderer:BitmapLineRenderer = new BitmapLineRenderer( new Rectangle( 0, 0, 500, 500 ) );
      renderer.addEmitter( emitter );
      addChild( renderer );
      
      emitter.start();
    }
  }
}
package
{
  import org.flintparticles.common.actions.Age;
  import org.flintparticles.common.actions.ScaleImage;
  import org.flintparticles.common.counters.Blast;
  import org.flintparticles.common.initializers.ColorInit;
  import org.flintparticles.common.initializers.Lifetime;
  import org.flintparticles.twoD.actions.Accelerate;
  import org.flintparticles.twoD.actions.Move;
  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 Grass extends Emitter2D
  {
    public function Grass()
    {
      counter = new Blast( 100 );
      
      addInitializer( new Position( new DiscZone( new Point( 0, 0 ), 40 ) ) );
      addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 80, 40, -5 * Math.PI / 8, -3 * Math.PI / 8 ) ) );
      addInitializer( new ColorInit( 0xFF006600, 0xFF009900 ) );
      addInitializer( new Lifetime( 7 ) );
      
      addAction( new Move() );
      addAction( new Age() );
      addAction( new ScaleImage( 4, 1 ) );
      addAction( new Accelerate( 0, 10 ) );
    }
  }
}
import flash.geom.Rectangle;

import org.flintparticles.common.actions.*;
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.x = 250;
emitter.y = 400;
emitter.counter = new Blast( 100 );

emitter.addInitializer( new Position( new DiscZone( new Point( 0, 0 ), 40 ) ) );
emitter.addInitializer( new Velocity( new DiscSectorZone( new Point( 0, 0 ), 80, 40, -5 * Math.PI / 8, -3 * Math.PI / 8 ) ) );
emitter.addInitializer( new ColorInit( 0xFF006600, 0xFF009900 ) );
emitter.addInitializer( new Lifetime( 7 ) );

emitter.addAction( new Move() );
emitter.addAction( new Age() );
emitter.addAction( new ScaleImage( 4, 1 ) );
emitter.addAction( new Accelerate( 0, 10 ) );

var renderer:BitmapLineRenderer = new BitmapLineRenderer( new Rectangle( 0, 0, 500, 500 ) );
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"
  width="500" height="500"
  backgroundColor="#000000">

<f:BitmapLineRenderer width="500" height="500">
  <f:emitters>
    <f:Emitter id="emitter" autoStart="true" x="250" y="400">
      <f:counter>
        <f:Blast startCount="100"/>
      </f:counter>
      <f:initializers>
        <f:Position>
          <f:DiscZone centerX="0" centerY="0" outerRadius="40"/>
        </f:Position>
        <f:Velocity>
          <f:DiscSectorZone centerX="0" centerY="0" outerRadius="80" innerRadius="40" minAngle="{-5 * Math.PI / 8}" maxAngle="{-3 * Math.PI / 8}"/>
        </f:Velocity>
        <f:ColorInit minColor="0xFF006600" maxColor="0xFF009900"/>
        <f:Lifetime lifetime="7"/>
      </f:initializers>
      <f:actions>
        <f:Move/>
        <f:Age/>
        <f:Accelerate x="0" y="10"/>
        <f:ScaleImage startScale="4" endScale="1"/>
      </f:actions>
    </f:Emitter>
  </f:emitters>
</f:BitmapLineRenderer>
</s:Application>