package  
{
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.flintparticles.common.actions.Age;
	import org.flintparticles.common.actions.Fade;
	import org.flintparticles.common.counters.Steady;
	import org.flintparticles.common.displayObjects.Dot;
	import org.flintparticles.common.displayObjects.RadialDot;
	import org.flintparticles.common.displayObjects.Rect;
	import org.flintparticles.common.energyEasing.Exponential;
	import org.flintparticles.common.initializers.Lifetime;
	import org.flintparticles.common.initializers.SharedImage;
	import org.flintparticles.common.initializers.SharedImages;
	import org.flintparticles.twoD.actions.Accelerate;
	import org.flintparticles.twoD.actions.Collide;
	import org.flintparticles.twoD.actions.MouseGravity;
	import org.flintparticles.twoD.actions.Move;
	import org.flintparticles.twoD.actions.RandomDrift;
	import org.flintparticles.twoD.actions.RotateToDirection;
	import org.flintparticles.twoD.actions.ScaleAll;
	import org.flintparticles.twoD.emitters.Emitter2D;
	import org.flintparticles.twoD.initializers.Position;
	import org.flintparticles.twoD.initializers.Velocity;
	import org.flintparticles.twoD.renderers.BitmapRenderer;
	import org.flintparticles.twoD.zones.LineZone;
	import org.flintparticles.twoD.zones.PointZone;
	import org.flintparticles.twoD.zones.RectangleZone;
	
	public class MyParticles extends Sprite
	{
		private var _isRunning:Boolean;
		
		private var renderer:BitmapRenderer;
		private var emitter:Emitter2D;
		
		public function MyParticles() 
		{
			_isRunning = false;
			
			renderer = new BitmapRenderer(new Rectangle(0, 0, 600, 400));
			addChild(renderer);
			
			emitter = new Emitter2D();
			emitter.counter = new Steady(20);
			
			var imageArray:Array = new Array();
			var weightArray:Array = new Array();
			imageArray.push(new Dot(2, 0xFFEEDD));
			weightArray.push(10);
			imageArray.push(new Dot(5, 0xAAEEDD));
			weightArray.push(10);
			imageArray.push(new RadialDot(5, 0xAAFFFF));
			weightArray.push(1);
			imageArray.push(new Rect(20, 10, 0xFFAAFF));
			weightArray.push(1);
			emitter.addInitializer(new SharedImages(imageArray, weightArray));
			
			var lineZone:LineZone = new LineZone(new Point(100, 300), new Point(500, 300));
			var position:Position = new Position(lineZone);			
			emitter.addInitializer(position);
			renderer.addEmitter(emitter);			
			emitter.addAction(new Move());			
			var velocityPointZone:PointZone = new PointZone(new Point(0, -150));
			emitter.addInitializer(new Velocity(velocityPointZone));			
			emitter.addAction(new Accelerate(0, 45));			
			emitter.addAction(new RandomDrift(50, 50));
			emitter.addInitializer(new Lifetime(5));
			emitter.addAction(new Age(Exponential.easeIn));
			emitter.addAction(new Fade());
			
			emitter.addAction(new ScaleAll(1, 5));
			emitter.addAction(new Collide(3));
			emitter.addAction(new RotateToDirection());
			emitter.addAction(new MouseGravity(200, renderer));
		}
		
		public function start():void
		{
			trace("Particles started");
			emitter.start();
			emitter.runAhead(10, 30);
			_isRunning = true;
		}
		
		public function stop():void
		{
			trace("Particles stopped");
			emitter.stop();
			_isRunning = false;
		}
		
		public function get isRunning():Boolean
		{
			return _isRunning;
		}
	}
}