Archive for December 31st, 2008

Happy New Year!

Wednesday, December 31st, 2008 | examples | Comments

Click to party ;)

Oh, and the code’s a mess.

source

package
{
	import flash.events.MouseEvent;
 
	import org.flintparticles.common.actions.Age;
	import org.flintparticles.common.counters.Blast;
	import org.flintparticles.common.counters.Steady;
	import org.flintparticles.common.energyEasing.Quadratic;
	import org.flintparticles.common.events.EmitterEvent;
	import org.flintparticles.common.events.ParticleEvent;
	import org.flintparticles.common.initializers.Lifetime;
	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.geom.Vector3D;
	import org.flintparticles.threeD.initializers.Position;
	import org.flintparticles.threeD.initializers.Rotation;
	import org.flintparticles.threeD.initializers.ScaleAllInit;
	import org.flintparticles.threeD.initializers.Velocity;
	import org.flintparticles.threeD.papervision3d.PV3DRenderer;
	import org.flintparticles.threeD.papervision3d.initializers.PV3DObjectClasses;
	import org.flintparticles.threeD.particles.Particle3D;
	import org.flintparticles.threeD.zones.ConeZone;
	import org.flintparticles.threeD.zones.LineZone;
	import org.flintparticles.threeD.zones.PointZone;
	import org.flintparticles.threeD.zones.SphereZone;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.view.BasicView;	
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class HappyNewYear extends BasicView
	{
		private var flintRenderer:PV3DRenderer;
		private var rocket:Emitter3D;
		private var cameraTarget:DisplayObject3D = DisplayObject3D.ZERO;
		private var previousMouseX:Number = 0;
		private var cameraYaw:Number = 0;
 
		public function HappyNewYear()
		{
			flintRenderer = new PV3DRenderer( scene );
			setupRocket();
			startRendering();
 
			stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
		}
 
		private function setupRocket():void
		{
			rocket = new Emitter3D();
			rocket.counter = new Steady( 1 );
 
			rocket.addInitializer( new PV3DObjectClasses([HappyWord, NewWord, YearWord]) );
			rocket.addInitializer( new ScaleAllInit(.9, 1.4));
			rocket.addInitializer( new Position( new LineZone( new Vector3D( 0, -500, 0 ), new Vector3D( 0, -500, 0) ) ) );
			rocket.addInitializer( new Velocity( new ConeZone( Vector3D.ZERO, Vector3D.AXISY, 1, 500, 330 ) ) );
			rocket.addInitializer( new Lifetime( 3.3 ) );
 
			rocket.addAction( new Age() );
			rocket.addAction( new Move() );
			rocket.addAction( new Accelerate( new Vector3D( 0, -50, 0 ) ) );
			rocket.addAction( new LinearDrag( 0.5 ) );
			rocket.addAction( new RandomDrift( 200, 200, 200 ) );
 
			rocket.addEventListener( ParticleEvent.PARTICLE_DEAD, rocket_particleDeadHandler, false, 0, true );
 
			flintRenderer.addEmitter(rocket);
 
			rocket.start();
		}
 
		private function rocket_particleDeadHandler(event:ParticleEvent):void
		{
			var explode:Emitter3D = new Emitter3D();
			explode.counter = new Blast( 10 );
 
			explode.addInitializer( new PV3DObjectClasses([HappyWord, NewWord, YearWord]) );
			explode.addInitializer( new ScaleAllInit(.3, .6));
			explode.addInitializer( new Rotation(Vector3D.AXISX, 1, 360));
			explode.addInitializer( new Rotation(Vector3D.AXISZ, 1, 360));
			explode.addInitializer( new Position( new PointZone( Particle3D( event.particle ).position ) ) );
			explode.addInitializer( new Velocity( new SphereZone( Vector3D.ZERO, 1000 ) ) );
			explode.addInitializer( new Lifetime( 3 ) );
 
			explode.addAction( new Age( Quadratic.easeIn ) );
			explode.addAction( new Move() );
			explode.addAction( new Accelerate( new Vector3D( 0, -500, 0 ) ) );
			explode.addAction( new LinearDrag( 0.5 ) );
 
 
			explode.addEventListener( EmitterEvent.EMITTER_EMPTY, explode_emitterEmptyHandler, false, 0, true );
			flintRenderer.addEmitter( explode );
			explode.start();
		}
 
		private function explode_emitterEmptyHandler(event:EmitterEvent):void
		{
			Emitter3D( event.target ).removeEventListener( EmitterEvent.EMITTER_EMPTY, explode_emitterEmptyHandler );
			flintRenderer.removeEmitter( Emitter3D( event.target ) );
		} 
 
		private function stage_mouseMoveHandler(event:MouseEvent):void
		{
			var differenceX:Number = event.stageX - previousMouseX;
			cameraYaw += differenceX;
			cameraYaw %= 360;
 
			previousMouseX = event.stageX;
 
			camera.orbit(90, cameraYaw, true, cameraTarget);
		}
 
	}
}
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.core.geom.TriangleMesh3D;
 
 
class HappyWord extends TriangleMesh3D
{
	public function HappyWord()
	{
		super( null, new Array(), new Array(), null );
		var word:Text3D = new Text3D("Happy", new HelveticaBold(), new Letter3DMaterial(0xfe5555));
		addChild(word);
	}	
}
 
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.core.geom.TriangleMesh3D;
 
 
class NewWord extends TriangleMesh3D
{
	public function NewWord()
	{
		super( null, new Array(), new Array(), null );
		var word:Text3D = new Text3D("New", new HelveticaBold(), new Letter3DMaterial(0x91c0ff));
		addChild(word);
	}	
}
 
 
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.core.geom.TriangleMesh3D;
	import org.papervision3d.typography.fonts.HelveticaBold;
 
 
class YearWord extends TriangleMesh3D
{
	public function YearWord()
	{
		super( null, new Array(), new Array(), null );
		var word:Text3D = new Text3D("Year", new HelveticaBold(), new Letter3DMaterial(0xfffbbb));
		addChild(word);
	}	
}

Tags: , ,

Search

Recommended Books

Speaking at FITC Toronto

 

December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...