In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

lorenz

Get Adobe Flash player
by hashimoto0623 18 Nov 2009
/**
 * Copyright hashimoto0623 ( http://wonderfl.net/user/hashimoto0623 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kauo
 */

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;

	[SWF(backgroundColor=0x000000)]
	
	public class lorenz extends Sprite{
		private var viewport:Viewport3D;
		private var scene:Scene3D;
		private var camera:Camera3D;
		private var renderer:BasicRenderEngine;
		private var rootNode:DisplayObject3D;
		private var light:PointLight3D;

		private var cube:Cube;
		private var fireFlag:Boolean=false;
		private var by_def:Number=170;
		private var bvy_def:Number=30;
		private var bva:Number=2;
		private var bvy:Number=bvy_def;
		private var brad:Number;
		private var tf:TextField;
		private var kstat:Array;
		private var spd:Number=0;
		private var maxspd:Number=40;
		private var cameraMode:Number=1;
		private var debug_mode:Boolean=false;
		private var parr:Array=new Array();
		private var pnum:Number=1;
		private var wfm:WireframeMaterial=new WireframeMaterial();
		private var fsm:FlatShadeMaterial;
		private var mls:MaterialsList;
		
		private var cube_rotY_targ:Number=30;
		private var cube_rotX_targ:Number=20;
		private var cube_scale:Number=500;
		
		private var dx:Number;
		private var dy:Number;
		private var dz:Number;
		private var px:Number=0;
		private var py:Number=3;
		private var pz:Number=1;
		
		public function lorenz(){
			this.init();	
		}
		
		public function init():void{
            //this.stage.scaleMode = "noScale"
			this.init3D();
            
            kstat=new Array();
            kstat['up']=0;
            kstat['down']=0;
            kstat['right']=0;
            kstat['left']=0;
		}

		private function init3D():void{
			this.viewport=new Viewport3D(640,480,true,true);
			this.viewport.interactive=true;
			this.addChild(viewport);
			this.renderer=new BasicRenderEngine();
			this.scene=new Scene3D();
			rootNode=this.scene.addChild(new DisplayObject3D("rootNode"));
			
			light=new PointLight3D(true);
			light.x=1000;
			light.z=-1000;
			light.y=1000;
			light.rotationX=70;
			
			fsm=new FlatShadeMaterial(light);
			fsm.fillAlpha=0.8;
			mls=new MaterialsList();
			mls.addMaterial(fsm,"front");
			mls.addMaterial(fsm,"back");
			mls.addMaterial(fsm,"right");
			mls.addMaterial(fsm,"left");
			mls.addMaterial(fsm,"top");
			mls.addMaterial(fsm,"bottom");
			
			var fm:WireframeMaterial=new WireframeMaterial();
			
			cube=new Cube(mls,50,10,10);
			cube.x=cube.y=cube.z=0;
			cube.x=0*cube_scale;
			cube.y=3*cube_scale;
			cube.z=1*cube_scale;
			cube.visible=false;
			rootNode.addChild(cube);
			
			
			//出バグ用TF
            this.tf=new TextField();
            this.tf.text=this.stage.width+":"+this.stage.height;
            this.tf.width=100;
            this.tf.height=100;
            stage.addChild(tf);
            
            
			camera=new Camera3D();
			camera.zoom=100;
            
			stage.addEventListener(Event.ENTER_FRAME,loop3d);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown);
			stage.addEventListener(KeyboardEvent.KEY_UP,keyup);
			
		}
		
		
		private function loop3d(e:Event):void{
			this.camera.y+=(this.mouseX-this.stage.width/2)/200;
			//this.rootNode.rotationX+=(this.mouseY-this.stage.height/2)/200;
			makeNextPlane(pnum);
			pnum++;
			renderer.renderScene(scene,camera,viewport);
		}
		
		private function makeNextPlane(pn:Number):void{
    		var rad2:Number=(cube.rotationY-90) * Math.PI / 180;
    		var rad3:Number=(cube.rotationX-90) * Math.PI / 180;
			
			cubeMove();
			parr[pn]=new Cube(mls,300,100,50);
			parr[pn].visible=true;
			parr[pn].alpha=0.5;
			if(pn>1){
				parr[pn].x=cube.x;
				parr[pn].y=cube.y;
				parr[pn].z=cube.z;
				parr[pn].lookAt(parr[pn-1]);

			}else parr[1].visible=false;
			rootNode.addChild(parr[pn]);
			if(pn>180){
				rootNode.removeChild(parr[pn-180]);
			}
			
			camera.x=cube.x;
			camera.y=cube.y;
			camera.z=cube.z-10000;
		}
		
		private function cubeMove():void{
			var xx:Number=cube.x/cube_scale;
			var yy:Number=cube.y/cube_scale;
			var zz:Number=cube.z/cube_scale;
			dx=10*(py-px);
			dy=px*(28-pz)-py;
			dz=px*py-(8/3)*pz;
			px+=dx*0.01;
			py+=dy*0.01;
			pz+=dz*0.01;
			cube.x=px*cube_scale;
			cube.y=py*cube_scale;
			cube.z=pz*cube_scale;
			tf.text=cube.x+":"+cube.y+":"+cube.z;
		}
		
        private function keydown(e:KeyboardEvent):void{
        	if(e.keyCode==37) this.kstat['left']	=true;
        	if(e.keyCode==38) this.kstat['up']		=true;
        	if(e.keyCode==39) this.kstat['right']	=true;
        	if(e.keyCode==40) this.kstat['down']	=true;
        	if(e.keyCode==32) {
        		cameraMode*=-1;
        		if(cameraMode==-1){
					camera.rotationX=0;
					camera.rotationY=0;
					camera.rotationZ=0;
        		}
        	}
        	
        }
        
        private function keyup(e:KeyboardEvent):void{
        	if(e.keyCode==37) this.kstat['left']	=false;
        	if(e.keyCode==38) this.kstat['up']		=false;
        	if(e.keyCode==39) this.kstat['right']	=false;
        	if(e.keyCode==40) this.kstat['down']	=false;
        }
	}
}