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

遠近感ブラー

package  
{
	import flash.display.*;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.filters.*;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	import flash.net.*;
	import flash.system.Security;
	import flash.text.*;
	import flash.ui.Keyboard;
	
	public class Moji extends Sprite
	{
		private var loader:URLLoader;
		private var filter:ShaderFilter;
		private var sprite:Sprite = new Sprite();
		private var back:Sprite = new Sprite();
		private var backBmp:BitmapData = new BitmapData(400, 400, true, 0xFF000000);
		private var theta:Number = 0.0;
		private var phi:Number = 0.0;
		private var spritePath:Vector.<Vector3D> = new Vector.<Vector3D>(7);
		private var path2:Vector.<Vector3D> = new Vector.<Vector3D>(7);
		
		public function Moji() 
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP;
			loader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.BINARY;
			loader.addEventListener(Event.COMPLETE, onComp);
			loader.load( new URLRequest("http://www.nyafuri.com/flash/blur.pbj"));
			this.x = 0;
			this.y = 0;
			spritePath[0] = new Vector3D(0, -60, 0);
			spritePath[1] = new Vector3D(170, -60, 0);
			spritePath[2] = new Vector3D(170, 60, 0);
			spritePath[3] = new Vector3D(0, 60, 0);
			spritePath[4] = new Vector3D(1, 0, 0);
			spritePath[5] = new Vector3D(0, 1, 0);
			spritePath[6] = new Vector3D(0, 0, 1);
		}
		private function onComp(event:Event):void {
			var shader:Shader = new Shader((event.currentTarget as URLLoader).data);
			shader.data.c.value = [3.0];
			shader.data.backImage.input = backBmp;
			stage.addEventListener(Event.ENTER_FRAME, onEnter);
			this.addChild( sprite );
			this.graphics.beginFill(0xFFFFFF, 0);
			this.graphics.drawRect(0, 0, 400, 400);
			var textfield:TextField = new TextField();
			textfield.multiline = true;
			textfield.defaultTextFormat = new TextFormat("_sans", 30);
			textfield.autoSize = TextFieldAutoSize.LEFT;
			textfield.text = "TEST TEST\nTEST TEST\nTEST TEST";
			textfield.y = -55;
			sprite.addChild( textfield );
			sprite.graphics.beginFill(0x0,0.4);
			sprite.graphics.drawRect( 0, -60, 170, 120);
			sprite.x = 200;
			sprite.y = 200;
			filter = new ShaderFilter(shader);
		}
		private function onEnter(event:Event):void {
			theta += 0.015625;
			phi += 0.125 * 0.015625;
			sprite.rotationX = phi * 180 / Math.PI;
			sprite.rotationY = theta * 180 / Math.PI;
			sprite.rotationZ = phi * 180 / Math.PI;
			
			var matrix2:Matrix3D = new Matrix3D();
			matrix2.appendRotation(sprite.rotationX, new Vector3D(1, 0, 0) );
			matrix2.appendRotation(sprite.rotationY, new Vector3D(0, 1, 0) );
			matrix2.appendRotation(sprite.rotationZ, new Vector3D(0, 0, 1) );
			var fartherIndex:int = 0;
			var zVector:Vector3D = new Vector3D();
			var xyVector:Vector3D = new Vector3D();
			for ( var i:int = 4; i < 6; i++ ) {
				path2[i] = matrix2.transformVector(spritePath[i]);
				var tempVec:Vector3D = path2[i].clone();
				tempVec.scaleBy( -path2[i].z );
				zVector = zVector.add( tempVec );
			}
			path2[i] = matrix2.transformVector(spritePath[i]);
			
			zVector.x = 200 + (zVector.x - 200) * 800 / ( zVector.z + 800 );
			zVector.y = (zVector.y) * 800 / ( zVector.z + 800 );
			xyVector = new Vector3D(zVector.x, zVector.y);
			var colorValue:int = Math.floor( Math.abs( zVector.z * 255 ));
			var matrixAngle:Number = Math.atan2( path2[i].y, path2[i].x );
			var matrix:Matrix = new Matrix();
			var scaleVar:Number = 400 * xyVector.length * 0.0006;
			matrix.rotate(matrixAngle);
			matrix.scale(scaleVar, scaleVar);
			matrix.translate(200, 200);
			back.graphics.clear();
			back.graphics.lineStyle(10);
			back.graphics.lineGradientStyle(
				GradientType.LINEAR,
				[0x10000 * colorValue, 0x0, 0x10000 * colorValue],
				[1, 1, 1], 
				[0, 127, 255], 
				matrix, 
				SpreadMethod.PAD
			);
			back.graphics.beginGradientFill(
				GradientType.LINEAR,
				[0x10000 * colorValue, 0x0, 0x10000 * colorValue],
				[1, 1, 1], 
				[0, 127, 255], 
				matrix, 
				SpreadMethod.PAD
			);
			back.graphics.drawRect(0, 0, 400, 400 );
			backBmp.draw( back );
			this.filters = [filter];
		}
	}
}