Firework Display
This project combines a number of emitters into a single display.
package { import org.flintparticles.common.emitters.Emitter; import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.events.ParticleEvent; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.particles.Particle3D; import org.flintparticles.threeD.renderers.BitmapRenderer; import org.flintparticles.threeD.renderers.controllers.FirstPersonCamera; import org.flintparticles.threeD.zones.LineZone; import flash.display.Sprite; import flash.filters.BlurFilter; import flash.filters.ColorMatrixFilter; import flash.geom.Rectangle; import flash.geom.Vector3D; [SWF(width='800', height='600', frameRate='60', backgroundColor='#000000')] public class Main extends Sprite { private var orbitter:FirstPersonCamera; private var renderer:BitmapRenderer; public function Main() { renderer = new BitmapRenderer( new Rectangle( -400, -300, 800, 600 ), false ); renderer.x = 400; renderer.y = 300; renderer.addFilter( new BlurFilter( 2, 2, 1 ) ); renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) ); addChild( renderer ); renderer.camera.position = new Vector3D( 0, -150, -400 ); renderer.camera.target = new Vector3D( 0, -150, 0 ); renderer.camera.projectionDistance = 400; orbitter = new FirstPersonCamera( stage, renderer.camera ); orbitter.start(); var emitter:Emitter3D = new Whizzer( new LineZone( new Vector3D( -200, 0, 0 ), new Vector3D( 200, 0, 0) ) ); renderer.addEmitter( emitter ); emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, whizzBang, false, 0, true ); emitter.start(); emitter = new Candle( new Vector3D( 150, 0, 150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new Candle( new Vector3D( -150, 0, 150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new Candle( new Vector3D( 150, 0, -150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new Candle( new Vector3D( -150, 0, -150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new CatherineWheel( new Vector3D( -200, -200, 50 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new CatherineWheel( new Vector3D( 0, -200, 50 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new CatherineWheel( new Vector3D( 200, -200, 50 ) ); renderer.addEmitter( emitter ); emitter.start(); } public function whizzBang( ev:ParticleEvent ):void { var bang:Emitter3D = new SphereBang( Particle3D( ev.particle ).position ); bang.addEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter, false, 0, true ); renderer.addEmitter( bang ); bang.start(); } public function removeEmitter( ev:EmitterEvent ):void { Emitter3D( ev.target ).removeEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter ); renderer.removeEmitter( Emitter3D( ev.target ) ); } public function destroy():void { for each( var e:Emitter in renderer.emitters ) { e.stop(); } } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Steady; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.initializers.SharedImage; import org.flintparticles.threeD.actions.Accelerate; import org.flintparticles.threeD.actions.Move; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.Position; import org.flintparticles.threeD.initializers.Velocity; import org.flintparticles.threeD.zones.DiscZone; import org.flintparticles.threeD.zones.PointZone; import flash.geom.Vector3D; public class Candle extends Emitter3D { public function Candle( position:Vector3D ) { counter = new Steady( 30 ); addInitializer( new SharedImage( new Dot( 1 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Position( new PointZone( position ) ) ); addInitializer( new Velocity( new DiscZone( new Vector3D( 0, -80, 0 ), new Vector3D( 0, 1, 0 ), 30 ) ) ); addInitializer( new Lifetime( 2 ) ); addAction( new Move() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new Age() ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Steady; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.initializers.SharedImage; import org.flintparticles.threeD.actions.Accelerate; import org.flintparticles.threeD.actions.Move; import org.flintparticles.threeD.activities.RotateEmitter; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.Velocity; import org.flintparticles.threeD.zones.ConeZone; import flash.geom.Vector3D; public class CatherineWheel extends Emitter3D { public function CatherineWheel( position:Vector3D ) { counter = new Steady( 80 ); this.position = position; addActivity( new RotateEmitter( new Vector3D( 0, 0, 1 ), 10 ) ); addInitializer( new SharedImage( new Dot( 1 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Velocity( new ConeZone( new Vector3D(), new Vector3D( 1, 0, 0 ), 0.5, 100, 80 ) ) ); addInitializer( new Lifetime( 0.5 ) ); addAction( new Move() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new Age() ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.actions.Fade; import org.flintparticles.common.counters.Blast; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.initializers.SharedImage; import org.flintparticles.threeD.actions.Accelerate; import org.flintparticles.threeD.actions.LinearDrag; import org.flintparticles.threeD.actions.Move; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.Position; import org.flintparticles.threeD.initializers.Velocity; import org.flintparticles.threeD.zones.PointZone; import org.flintparticles.threeD.zones.SphereZone; import flash.geom.Vector3D; public class SphereBang extends Emitter3D { public function SphereBang( position:Vector3D ) { counter = new Blast( 200 ); addInitializer( new SharedImage( new Dot( 1 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Position( new PointZone( position ) ) ); addInitializer( new Velocity( new SphereZone( new Vector3D(), 100 ) ) ); addInitializer( new Lifetime( 3 ) ); addAction( new Age( Quadratic.easeIn ) ); addAction( new Move() ); addAction( new Fade() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new LinearDrag( 0.5 ) ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Steady; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.initializers.SharedImage; import org.flintparticles.threeD.actions.Accelerate; import org.flintparticles.threeD.actions.LinearDrag; import org.flintparticles.threeD.actions.Move; import org.flintparticles.threeD.actions.RandomDrift; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.Position; import org.flintparticles.threeD.initializers.Velocity; import org.flintparticles.threeD.zones.ConeZone; import org.flintparticles.threeD.zones.Zone3D; import flash.geom.Vector3D; public class Whizzer extends Emitter3D { public function Whizzer( zone:Zone3D ) { counter = new Steady( 0.5 ); addInitializer( new SharedImage( new Dot( 4 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Position( zone ) ); addInitializer( new Velocity( new ConeZone( new Vector3D(), new Vector3D( 0, -1, 0 ), 0.1, 350, 330 ) ) ); addInitializer( new Lifetime( 3.3 ) ); addAction( new Age() ); addAction( new Move() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new LinearDrag( 0.5 ) ); addAction( new RandomDrift( 10, 10, 10 ) ); } } }
import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.common.events.ParticleEvent; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.particles.Particle3D; import org.flintparticles.threeD.renderers.*; import org.flintparticles.threeD.renderers.controllers.FirstPersonCamera; import org.flintparticles.threeD.zones.LineZone; var renderer:BitmapRenderer = new BitmapRenderer( new Rectangle( -400, -300, 800, 600 ), false ); renderer.x = 400; renderer.y = 300; renderer.addFilter( new BlurFilter( 2, 2, 1 ) ); renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) ); addChild( renderer ); renderer.camera.position = new Vector3D( 0, -150, -400 ); renderer.camera.target = new Vector3D( 0, -150, 0 ); renderer.camera.projectionDistance = 400; var orbitter:FirstPersonCamera = new FirstPersonCamera( stage, renderer.camera ); orbitter.start(); var emitter:Emitter3D = new Whizzer( new LineZone( new Vector3D( -200, 0, 0 ), new Vector3D( 200, 0, 0) ) ); renderer.addEmitter( emitter ); emitter.addEventListener( ParticleEvent.PARTICLE_DEAD, whizzBang, false, 0, true ); emitter.start(); emitter = new Candle( new Vector3D( 150, 0, 150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new Candle( new Vector3D( -150, 0, 150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new Candle( new Vector3D( 150, 0, -150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new Candle( new Vector3D( -150, 0, -150 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new CatherineWheel( new Vector3D( -200, -200, 50 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new CatherineWheel( new Vector3D( 0, -200, 50 ) ); renderer.addEmitter( emitter ); emitter.start(); emitter = new CatherineWheel( new Vector3D( 200, -200, 50 ) ); renderer.addEmitter( emitter ); emitter.start(); function whizzBang( ev:ParticleEvent ):void { var bang:Emitter3D = new SphereBang( Particle3D( ev.particle ).position ); bang.addEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter, false, 0, true ); renderer.addEmitter( bang ); bang.start(); } function removeEmitter( ev:EmitterEvent ):void { ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter ); renderer.removeEmitter( Emitter3D( ev.target ) ); }
package { import org.flintparticles.common.actions.*; import org.flintparticles.common.counters.*; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.initializers.*; import org.flintparticles.threeD.actions.*; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.*; import org.flintparticles.threeD.zones.*; import flash.geom.Vector3D; public class Candle extends Emitter3D { public function Candle( position:Vector3D ) { counter = new Steady( 30 ); addInitializer( new SharedImage( new Dot( 1 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Position( new PointZone( position ) ) ); addInitializer( new Velocity( new DiscZone( new Vector3D( 0, -80, 0 ), new Vector3D( 0, 1, 0 ), 30 ) ) ); addInitializer( new Lifetime( 2 ) ); addAction( new Move() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new Age() ); } } }
package { import org.flintparticles.common.actions.Age; import org.flintparticles.common.counters.Steady; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.initializers.ColorInit; import org.flintparticles.common.initializers.Lifetime; import org.flintparticles.common.initializers.SharedImage; import org.flintparticles.threeD.actions.Accelerate; import org.flintparticles.threeD.actions.Move; import org.flintparticles.threeD.activities.RotateEmitter; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.Velocity; import org.flintparticles.threeD.zones.ConeZone; import flash.geom.Vector3D; public class CatherineWheel extends Emitter3D { public function CatherineWheel( position:Vector3D ) { counter = new Steady( 80 ); this.position = position; addActivity( new RotateEmitter( new Vector3D( 0, 0, 1 ), 10 ) ); addInitializer( new SharedImage( new Dot( 1 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Velocity( new ConeZone( new Vector3D(), new Vector3D( 1, 0, 0 ), 0.5, 100, 80 ) ) ); addInitializer( new Lifetime( 0.5 ) ); addAction( new Move() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new Age() ); } } }
package { import org.flintparticles.common.actions.*; import org.flintparticles.common.counters.*; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.easing.Quadratic; import org.flintparticles.common.initializers.*; import org.flintparticles.threeD.actions.*; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.*; import org.flintparticles.threeD.zones.*; import flash.geom.Vector3D; public class SphereBang extends Emitter3D { public function SphereBang( position:Vector3D ) { counter = new Blast( 200 ); addInitializer( new SharedImage( new Dot( 1 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Position( new PointZone( position ) ) ); addInitializer( new Velocity( new SphereZone( new Vector3D(), 100 ) ) ); addInitializer( new Lifetime( 3 ) ); addAction( new Age( Quadratic.easeIn ) ); addAction( new Move() ); addAction( new Fade() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new LinearDrag( 0.5 ) ); } } }
package { import org.flintparticles.common.actions.*; import org.flintparticles.common.counters.*; import org.flintparticles.common.displayObjects.Dot; import org.flintparticles.common.initializers.*; import org.flintparticles.threeD.actions.*; import org.flintparticles.threeD.emitters.Emitter3D; import org.flintparticles.threeD.initializers.*; import org.flintparticles.threeD.zones.*; import flash.geom.Vector3D; public class Whizzer extends Emitter3D { public function Whizzer( zone:Zone3D ) { counter = new Steady( 0.5 ); addInitializer( new SharedImage( new Dot( 4 ) ) ); addInitializer( new ColorInit( 0xFFFFFF00, 0xFFFF6600 ) ); addInitializer( new Position( zone ) ); addInitializer( new Velocity( new ConeZone( new Vector3D(), new Vector3D( 0, -1, 0 ), 0.1, 350, 330 ) ) ); addInitializer( new Lifetime( 3.3 ) ); addAction( new Age() ); addAction( new Move() ); addAction( new Accelerate( new Vector3D( 0, 50, 0 ) ) ); addAction( new LinearDrag( 0.5 ) ); addAction( new RandomDrift( 10, 10, 10 ) ); } } }
<?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/flint3d" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*" xmlns="*" width="800" height="600" backgroundColor="#000000" creationComplete="created()"> <fx:Script> <![CDATA[ import org.flintparticles.common.events.EmitterEvent; import org.flintparticles.threeD.particles.Particle3D; import org.flintparticles.common.events.ParticleEvent; private function created():void { whizzer.addEventListener( ParticleEvent.PARTICLE_DEAD, whizzBang, false, 0, true ); } public function whizzBang( ev:ParticleEvent ):void { var bang:SphereBang = new SphereBang(); bang.position = Particle3D( ev.particle ).position; bang.addEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter, false, 0, true ); renderer.addEmitter( bang ); bang.start(); } public function removeEmitter( ev:EmitterEvent ):void { SphereBang( ev.target ).removeEventListener( EmitterEvent.EMITTER_EMPTY, removeEmitter ); renderer.removeEmitter( SphereBang( ev.target ) ); } ]]> </fx:Script> <f:BitmapRenderer x="0" y="0" id="renderer" width="800" height="600"> <f:camera> <f:Camera id="camera" projectionDistance="400"> <f:position> <geom:Vector3D x="0" y="-150" z="-400"/> </f:position> <f:target> <geom:Vector3D x="0" y="-150" z="0"/> </f:target> <f:controller> <f:FirstPersonCamera/> </f:controller> </f:Camera> </f:camera> <f:preFilters> <filters:BlurFilter blurX="2" blurY="2" quality="1"/> <filters:ColorMatrixFilter matrix="{[ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ]}"/> </f:preFilters> <f:emitters> <Whizzer id="whizzer" autoStart="true"> <zone> <f:LineZone> <f:start> <geom:Vector3D x="-200" y="0" z="0"/> </f:start> <f:end> <geom:Vector3D x="200" y="0" z="0"/> </f:end> </f:LineZone> </zone> </Whizzer> <CatherineWheel autoStart="true"> <position> <geom:Vector3D x="-200" y="-200" z="50"/> </position> </CatherineWheel> <CatherineWheel autoStart="true"> <position> <geom:Vector3D x="0" y="-200" z="50"/> </position> </CatherineWheel> <CatherineWheel autoStart="true"> <position> <geom:Vector3D x="200" y="-200" z="50"/> </position> </CatherineWheel> <Candle autoStart="true"> <position> <geom:Vector3D x="150" y="0" z="150"/> </position> </Candle> <Candle autoStart="true"> <position> <geom:Vector3D x="-150" y="0" z="150"/> </position> </Candle> <Candle autoStart="true"> <position> <geom:Vector3D x="150" y="0" z="-150"/> </position> </Candle> <Candle autoStart="true"> <position> <geom:Vector3D x="-150" y="0" z="-150"/> </position> </Candle> </f:emitters> </f:BitmapRenderer> </s:Application>
<?xml version="1.0" encoding="utf-8"?> <f:Emitter xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:f="http://flintparticles.org/2009/flint3d" xmlns:geom="flash.geom.*"> <f:counter> <f:Steady rate="30"/> </f:counter> <f:initializers> <f:SharedImage> <f:Dot radius="1"/> </f:SharedImage> <f:ColorInit minColor="0xFFFF6600" maxColor="0xFFFFFF00"/> <f:Velocity> <f:DiscZone outerRadius="30"> <f:normal> <geom:Vector3D x="0" y="1" z="0"/> </f:normal> <f:center> <geom:Vector3D x="0" y="-80" z="0"/> </f:center> </f:DiscZone> </f:Velocity> <f:Lifetime lifetime="2"/> </f:initializers> <f:actions> <f:Move/> <f:Age/> <f:Accelerate x="0" y="50" z="0"/> </f:actions> </f:Emitter>
<?xml version="1.0" encoding="utf-8"?> <f:Emitter xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:f="http://flintparticles.org/2009/flint3d" xmlns:geom="flash.geom.*"> <f:counter> <f:Steady rate="80"/> </f:counter> <f:activities> <f:RotateEmitter rotateSpeed="10"> <f:axis> <geom:Vector3D x="0" y="0" z="1"/> </f:axis> </f:RotateEmitter> </f:activities> <f:initializers> <f:SharedImage> <f:Dot radius="1"/> </f:SharedImage> <f:ColorInit minColor="0xFFFF6600" maxColor="0xFFFFFF00"/> <f:Velocity> <f:ConeZone angle="0.5" height="100" truncatedHeight="80"> <f:axis> <geom:Vector3D x="1" y="0" z="0"/> </f:axis> </f:ConeZone> </f:Velocity> <f:Lifetime lifetime="0.5"/> </f:initializers> <f:actions> <f:Move/> <f:Age/> <f:Accelerate x="0" y="50" z="0"/> </f:actions> </f:Emitter>
<?xml version="1.0" encoding="utf-8"?> <f:Emitter xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:f="http://flintparticles.org/2009/flint3d" xmlns:geom="flash.geom.*"> <fx:Script> <![CDATA[ import org.flintparticles.common.easing.Quadratic; ]]> </fx:Script> <f:counter> <f:Blast startCount="200"/> </f:counter> <f:initializers> <f:SharedImage> <f:Dot radius="1"/> </f:SharedImage> <f:ColorInit minColor="0xFFFF6600" maxColor="0xFFFFFF00"/> <f:Velocity> <f:SphereZone outerRadius="100"/> </f:Velocity> <f:Lifetime lifetime="3"/> </f:initializers> <f:actions> <f:Move/> <f:Fade/> <f:Age easing="{Quadratic.easeIn}"/> <f:Accelerate x="0" y="50" z="0"/> <f:LinearDrag drag="0.5"/> </f:actions> </f:Emitter>
<?xml version="1.0" encoding="utf-8"?> <f:Emitter xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:f="http://flintparticles.org/2009/flint3d" xmlns:geom="flash.geom.*"> <fx:Script> <![CDATA[ import org.flintparticles.threeD.zones.Zone3D; [Bindable] public var zone:Zone3D; ]]> </fx:Script> <f:counter> <f:Steady rate="0.5"/> </f:counter> <f:initializers> <f:SharedImage> <f:Dot radius="4"/> </f:SharedImage> <f:ColorInit minColor="0xFFFF6600" maxColor="0xFFFFFF00"/> <f:Position zone="{zone}"/> <f:Velocity> <f:ConeZone angle="0.1" height="350" truncatedHeight="330"> <f:axis> <geom:Vector3D x="0" y="-1" z="0"/> </f:axis> </f:ConeZone> </f:Velocity> <f:Lifetime lifetime="3.3"/> </f:initializers> <f:actions> <f:Move/> <f:Age/> <f:Accelerate x="0" y="50" z="0"/> <f:LinearDrag drag="0.5"/> <f:RandomDrift driftX="10" driftY="10" driftZ="10"/> </f:actions> </f:Emitter>