Rain
This example uses a simple rain simulation and a collision zone to bounce the rain off the umbrella.
package { import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.renderers.PixelRenderer; import flash.display.Bitmap; import flash.display.Sprite; import flash.geom.Rectangle; [SWF(width='600', height='400', frameRate='60', backgroundColor='#000000')] public class Main extends Sprite { private var emitter:Emitter2D; public function Main() { emitter = new Rain(); addChild( new Bitmap( new Image1( 600, 400 ) ) ); var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 600, 400 ) ); renderer.addEmitter( emitter ); addChild( renderer ); emitter.start(); emitter.runAhead( 4, 30 ); } } }
package { import org.flintparticles.common.counters.Steady; import org.flintparticles.common.initializers.AlphaInit; import org.flintparticles.twoD.actions.Accelerate; import org.flintparticles.twoD.actions.CollisionZone; import org.flintparticles.twoD.actions.DeathZone; import org.flintparticles.twoD.actions.Move; import org.flintparticles.twoD.actions.SpeedLimit; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.Position; import org.flintparticles.twoD.initializers.Velocity; import org.flintparticles.twoD.zones.DiscZone; import org.flintparticles.twoD.zones.LineZone; import org.flintparticles.twoD.zones.RectangleZone; import flash.geom.Point; public class Rain extends Emitter2D { public function Rain() { counter = new Steady( 1000 ); addInitializer( new Position( new LineZone( new Point( -55, -5 ), new Point( 605, -5 ) ) ) ); addInitializer( new Velocity( new DiscZone( new Point( 60, 400 ), 20 ) ) ); addInitializer( new AlphaInit( 0.5 ) ); addAction( new Move() ); addAction( new CollisionZone( new DiscZone( new Point( 245, 275 ), 150 ), 0.3 ) ); addAction( new DeathZone( new RectangleZone( -60, -10, 610, 410 ), true ) ); addAction( new Accelerate( 0, 500 ) ); addAction( new SpeedLimit( 500 ) ); } } }
import org.flintparticles.common.counters.Steady; import org.flintparticles.common.initializers.AlphaInit; import org.flintparticles.twoD.actions.Accelerate; import org.flintparticles.twoD.actions.CollisionZone; import org.flintparticles.twoD.actions.DeathZone; import org.flintparticles.twoD.actions.Move; import org.flintparticles.twoD.actions.RotateToDirection; import org.flintparticles.twoD.actions.SpeedLimit; import org.flintparticles.twoD.emitters.Emitter2D; import org.flintparticles.twoD.initializers.Position; import org.flintparticles.twoD.initializers.Velocity; import org.flintparticles.twoD.renderers.PixelRenderer; import org.flintparticles.twoD.zones.DiscZone; import org.flintparticles.twoD.zones.LineZone; import org.flintparticles.twoD.zones.RectangleZone; import flash.display.Sprite; import flash.geom.Rectangle; var emitter:Emitter2D = new Emitter2D(); emitter.counter = new Steady( 1000 ); emitter.addInitializer( new Position( new LineZone( new Point( -55, -5 ), new Point( 605, -5 ) ) ) ); emitter.addInitializer( new Velocity( new DiscZone( new Point( 60, 400 ), 20 ) ) ); emitter.addInitializer( new AlphaInit( 0.5 ) ); emitter.addAction( new Move() ); emitter.addAction( new CollisionZone( new DiscZone( new Point( 245, 275 ), 150 ), 0.3 ) ); emitter.addAction( new DeathZone( new RectangleZone( -60, -10, 610, 410 ), true ) ); emitter.addAction( new Accelerate( 0, 500 ) ); emitter.addAction( new SpeedLimit( 500 ) ); var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 600, 400 ) ); renderer.addEmitter( emitter ); addChild( renderer ); emitter.start(); emitter.runAhead( 4, 30 );
<?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:mx="library://ns.adobe.com/flex/mx" xmlns:f="http://flintparticles.org/2009/flint2d" width="600" height="400" backgroundColor="#000000"> <s:BitmapImage source="{new Image1( 600, 400 )}" width="600" height="400"/> <f:PixelRenderer id="renderer" width="600" height="400"> <f:emitters> <f:Emitter id="emitter" autoStart="true" runAheadTime="4" runAheadFrameRate="30"> <f:counter> <f:Steady rate="1000"/> </f:counter> <f:initializers> <f:Position> <f:LineZone startX="-55" startY="-5" endX="605" endY="-5"/> </f:Position> <f:Velocity> <f:DiscZone centerX="60" centerY="400" outerRadius="20"/> </f:Velocity> <f:AlphaInit alpha="0.5"/> </f:initializers> <f:actions> <f:Move/> <f:DeathZone zoneIsSafe="true"> <f:RectangleZone left="-60" right="610" top="-10" bottom="410"/> </f:DeathZone> <f:Accelerate x="0" y="500"/> <f:SpeedLimit limit="500"/> <f:CollisionZone bounce="0.3"> <f:DiscZone centerX="245" centerY="275" outerRadius="150"/> </f:CollisionZone> </f:actions> </f:Emitter> </f:emitters> </f:PixelRenderer> </s:Application>