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

forked from: 画面ぱりーんエフェクト forked from: adobe challenge 1

やっぱり1回しかできない…
Get Adobe Flash player
by Nicolas 02 Sep 2009
    Embed
/**
 * Copyright Nicolas ( http://wonderfl.net/user/Nicolas )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/njX8
 */

// forked from Nicolas's 画面ぱりーんエフェクト forked from: adobe challenge 1
// forked from checkmate's adobe challenge 1

//やっぱり1回しかできない…

package {
	import adobe.utils.CustomActions;
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Matrix3D;
	import flash.geom.Point;
	import flash.geom.Vector3D;
        import flash.net.URLRequest;
        import flash.system.LoaderContext;
	
	
[SWF(backgroundColor="0x000000")]
	public class BreakEffectSample extends Sprite {
		private var vertices:Vector.<Number> = new Vector.<Number>();
		private var points:Vector.<Number> = new Vector.<Number>();
		private var indices:Vector.<int> = new Vector.<int>();
		private var uvtData:Vector.<Number> = new Vector.<Number>();
		private var focalLength:Number = 700;
		
		private var omegas:Vector.<Vector3D> = new Vector.<Vector3D>();
		private var velocities:Vector.<Vector3D> = new Vector.<Vector3D>();
		
		private var srcBD:BitmapData = new BitmapData(400, 300, true, 0x000000);
		private var devideNum:int = 7;
		private var container:Sprite;
		private var g:Graphics;
		private var loader:Loader;
		
		
		public function BreakEffectSample() {
			//他に絵がないのです
                        const URL:String = "http://assets.wonderfl.net/images/related_images/b/be/befb/befb21fdbb5f07c2516e67716722abe12cf78ac2"
			var urlReq:URLRequest = new URLRequest(URL); 
                        loader = new Loader();
                        loader.load(urlReq, new LoaderContext(true));
                        
                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
			
			container = new Sprite();
			addChild(container);
			g = container.graphics;
			initVertexData();

			
			addEventListener(MouseEvent.CLICK, clickHandler);
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private function initVertexData():void {
                        var stepX:Number = srcBD.width / devideNum;
			var stepY:Number = srcBD.height / devideNum;
			var index:int = 0;
			for (var j:int = 0; j < devideNum; j++) {
				for (var i:int = 0; i < devideNum; i++) {
					setVertexData(i * stepX, j * stepY, 0, true);
					setVertexData((i + 1) * stepX, j * stepY, 0, true);
					setVertexData((i + 1) * stepX, (j + 1) * stepY, 0, true);
					setVertexData(i * stepX, j * stepY, 0, true);
					setVertexData(i * stepX, (j + 1) * stepY, 0, true);
					setVertexData((i + 1) * stepX, (j + 1) * stepY, 0, true);
					
					indices.push(index, index + 1, index + 2, index + 3, index + 4, index + 5);
					index = index + 6;
				}
			}
                        
                }

		private function setVertexData(_x:Number, _y:Number, _z:Number, uvtSet:Boolean):void {
			points.push(_x, _y, _z);
			var t:Number = focalLength / (focalLength + _z);
			vertices.push(_x * t, _y * t);
			if(uvtSet == true) uvtData.push(_x / srcBD.width, _y / srcBD.height, t);
		}

                private function completeHandler(e:Event):void {
                    var bmp:Bitmap = new Bitmap(srcBD);
                    var m:Matrix = new Matrix();
		    m.scale(srcBD.width / loader.content.width, srcBD.height / loader.content.height);
                    srcBD.draw(loader, m);
                    
		}

		private function clickHandler(e:MouseEvent):void {
			omegas = new Vector.<Vector3D>();
			velocities = new Vector.<Vector3D>();
			for (var i:int = 0; i < points.length / 9; i++) {
				var omega:Vector3D = new Vector3D();
				var velocity:Vector3D = new Vector3D();
				omega.x = Math.random() * 20 - 10;
				omega.y = Math.random() * 30 - 15;
				omega.z = Math.random() * 50 - 25;
				omegas.push(omega);
				velocity.x = Math.random() * 20 - 10;
				velocity.y = Math.random() * 2 + 1;
				velocity.z = Math.random() * 5 - 2.5;
				velocities.push(velocity);
			}
		}
		
		private function enterFrameHandler(e:Event):void {
			if(omegas.length > 0) {
				var pointsTemp:Vector.<Number> = points;
				points = new Vector.<Number>();
				vertices = new Vector.<Number>();
				var outOfScreenNum:Number = 0;
				for (var i:int = 0; i < pointsTemp.length / 9; i++) {
					
					var vectorTemp:Vector.<Number> = new Vector.<Number>();
					//3点分取り出す
					for (var index:int = 0; index < 9; index++) {
						vectorTemp.push(pointsTemp[i * 9 + index]);
					}
					var centerX:Number = (vectorTemp[0] + vectorTemp[3] + vectorTemp[6]) / 3;
					var centerY:Number = (vectorTemp[1] + vectorTemp[4] + vectorTemp[7]) / 3;
					var centerZ:Number = (vectorTemp[2] + vectorTemp[5] + vectorTemp[8]) / 3;
					
					    var mat:Matrix3D = new Matrix3D();
					    mat.identity();
					    mat.appendTranslation( -centerX, -centerY, -centerZ);
					    mat.appendRotation(omegas[i].x, Vector3D.X_AXIS);
					    mat.appendRotation(omegas[i].y, Vector3D.Y_AXIS);
					    mat.appendRotation(omegas[i].z, Vector3D.Z_AXIS);
					    mat.appendTranslation(centerX, centerY, centerZ);
                                            velocities[i].y += 0.1;
					    mat.appendTranslation(velocities[i].x, velocities[i].y, velocities[i].z);
					
					    mat.transformVectors(vectorTemp, vectorTemp);
					    setVertexData(vectorTemp[0], vectorTemp[1], vectorTemp[2], false);
					    setVertexData(vectorTemp[3], vectorTemp[4], vectorTemp[5], false);
					    setVertexData(vectorTemp[6], vectorTemp[7], vectorTemp[8], false);
                                        if(centerX >= 0 && centerX <= 400 && centerY <= 400 && centerZ > -300) {
                                        } else {
                                            outOfScreenNum++;
                                        }
				}
				if(outOfScreenNum > devideNum * devideNum *1.99) {
                                    omegas = new Vector.<Vector3D>();
                                    velocities = new Vector.<Vector3D>();
                                    vertices = new Vector.<Number>();
                                    indices = new Vector.<int>();
                                    uvtData = new Vector.<Number>();
                                    initVertexData();
                                    outOfScreenNum = 0;
			        }
                        
			}
                        g.clear();
			g.beginBitmapFill(srcBD);
			g.drawTriangles(vertices, indices, uvtData);
			g.endFill();
                        
		}
	}
	
}