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

【PV3D】study3 motion sample

... wonderfl本 + clockmakerさんのロジックで並び替えモーションサンプル
@author rettuce
Get Adobe Flash player
by rettuce 13 Jun 2010
/**
 * Copyright rettuce ( http://wonderfl.net/user/rettuce )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8wu9
 */

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
	import flash.geom.Point;
    import org.libspark.betweenas3.*;
    import org.libspark.betweenas3.easing.*;
    import org.libspark.betweenas3.tweens.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.utils.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.view.*;
	import org.papervision3d.events.InteractiveScene3DEvent;
	
	[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 30)]
	/**
	 * ... wonderfl本 + clockmakerさんのロジックで並び替えモーションサンプル
	 * @author rettuce
	 */
	public class DocumentClass extends BasicView 
	{
		private const PIXEL_NUM       :int    =  30;         //  枚数   
		private const MAX_CIRCLE       :int    =  250;         //  円の大きさ  
        private const MAX_RADIUS    :int    = 500;  // 空間の大きさ
        private const PLANE_SIZE    :int    = 50;       // パーティクルのサイズ
        private const PLANE_MARGIN  :int    = 10;     // パーティクルの余白
        private var pixelArr        :Array  = [];     // パーティクルを格納する配列
        private var dmyPixels       :Array  = [];     // ダミーパーティクルを格納する配列
        private var dmyObjs         :Array  = [];     // ダミー配列を格納する配列
		
        private var _index           :int    = 0;      // 形状のインデックス番号
        private var _indexNum           :int    = 5;      // 形状の種類
		private var _flag				:Boolean = false;       // 形状の出しわけ
		private var _timer:Timer = new Timer(5000);
		
		public function DocumentClass()
		{
			super( 0, 0, true, true, "Target" );
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			main();
		}
		
		private function main():void
		{
			viewport.buttonMode = true;
			
			// カメラの位置
            camera.z = -MAX_RADIUS;
			
			_timer.addEventListener(TimerEvent.TIMER, loop);
			_timer.start();
			
			// 初期化
			initSet();
			
			// モーションを100ミリ秒遅らせてスタート。直後だと座標取得ができないらしい。
			setTimeout(loop, 100);
			
			// レンダリング
			startRendering();
		}
		
		private function initSet():void
		{			
			// パーティクル生成
			var material:ColorMaterial = new ColorMaterial(0xFF0000, 1, true)
			material.doubleSided = true;
			
			pixelArr = [];
			for (var i:int = 0; i < PIXEL_NUM; i++)
			{
				var o:Plane = new Plane(material, PLANE_SIZE, PLANE_SIZE);
				o.addEventListener(InteractiveScene3DEvent.OBJECT_RELEASE, clickHandler);
				o.useOwnContainer = true;
				scene.addChild(o);
				pixelArr[i] = o;
				
				var point:Point = Point.polar( MAX_CIRCLE , ((360 / PIXEL_NUM) * i * Math.PI / 180));
				
				o.x = point.x;
				o.y = point.y;
				o.z = MAX_RADIUS * (Math.random() - 0.5)/2;
				o.rotationZ += (360 / PIXEL_NUM) * i;
			}
			dmySet();
		}
		
		
		private function dmySet():void
		{
            // 形状を決める
			if ( _index > _indexNum) _index = 0;
			if (dmyObjs.length == 1) scene.removeChild(dmyObjs[0]);
			
           // ダミーのピクセルを生成
            dmyPixels = [];
			dmyObjs[0] = new DisplayObject3D();
			scene.addChild(dmyObjs[0]);
			
			if ( _index == 0){												// 最大円
				for (var i:int = 0; i < PIXEL_NUM; i++) {
					dmyPixels[i] = [];				
					var point:Point = Point.polar( MAX_CIRCLE , ((360 / PIXEL_NUM) * i * Math.PI / 180));
					
					dmyPixels[i] = new DisplayObject3D();
					//dmyPixels[i] = new Plane(new WireframeMaterial(), PLANE_SIZE, PLANE_SIZE);
					dmyPixels[i].x = point.x;
					dmyPixels[i].y = point.y;
					dmyPixels[i].rotationZ = (360 / PIXEL_NUM) * i;				
					dmyObjs[0].addChild(dmyPixels[i]);
				}
				
				
				
			} else if ( _index == 1) {										// 円2つ
				var circleArr1:Array = [];	
				var circleArr2:Array = [];	
				for (var m:int = 0; m < PIXEL_NUM; m++) { // 適当に2分割
					if (Math.random() >= 0.6) {
						circleArr1.push(m);
					}else{
						circleArr2.push(m);
					}
				}
				if ( circleArr1.length >= circleArr2.length ) {
					var bC:Array = circleArr1;
					var sC:Array = circleArr2;
				} else {
					var bC:Array = circleArr2;
					var sC:Array = circleArr1;
				}
				
				for (var i:int = 0; i < PIXEL_NUM; i++) 
				{
					var point:Point;
					var ang:Number;
					
					if (bC.indexOf(i) != -1) {
							var bi:int = bC.indexOf(i);
							point = Point.polar( bC.length / PIXEL_NUM * MAX_CIRCLE , ((360 / bC.length) * bi * Math.PI / 180));
							point.x -= MAX_RADIUS / 3;
							ang = (360 / bC.length) * bi;
					} else {
							var si:int = sC.indexOf(i);
							point = Point.polar( sC.length /PIXEL_NUM*MAX_CIRCLE , ((360 / sC.length) * si * Math.PI / 180));
							point.x += MAX_RADIUS / 3;
							ang = (360 / sC.length) * si;
					}
					dmyPixels[i] = [];				
					
					dmyPixels[i] = new DisplayObject3D();
					//dmyPixels[i] = new Plane(new WireframeMaterial(), PLANE_SIZE, PLANE_SIZE);
					dmyPixels[i].x = point.x;
					dmyPixels[i].y = point.y;
					dmyPixels[i].rotationZ = ang;
					dmyObjs[0].addChild(dmyPixels[i]);
				}
				
				
				
			} else if ( _index == 2){										// 円3つ
				var circleArr1:Array = [];	
				var circleArr2:Array = [];	
				var circleArr3:Array = [];	
				for (var m:int = 0; m < PIXEL_NUM; m++) { // 適当に3分割
				 var num:Number = Math.random();
					if ( num <= 0.5) {
						circleArr1.push(m);
					} else if ( 0.5 < num && num <= 0.85) {
						circleArr2.push(m);
					} else if ( 0.85 < num ) {
						circleArr3.push(m);
					}
				}
				if ( circleArr1.length >= circleArr2.length &&  circleArr1.length >= circleArr3.length ) {
					var bC:Array = circleArr1;
					if ( circleArr2.length >= circleArr3.length ) {
						var mC:Array = circleArr2;
						var sC:Array = circleArr3;
					} else {
						var mC:Array = circleArr3;
						var sC:Array = circleArr2;
					}
				} else if  ( circleArr2.length >= circleArr1.length &&  circleArr2.length >= circleArr3.length ) {
					var bC:Array = circleArr2;
					if ( circleArr1.length >= circleArr3.length ) {
						var mC:Array = circleArr1;
						var sC:Array = circleArr3;
					} else {
						var mC:Array = circleArr3;
						var sC:Array = circleArr1;
					}
				} else if  ( circleArr3.length >= circleArr1.length &&  circleArr3.length >= circleArr2.length ) {
					var bC:Array = circleArr3;
					if ( circleArr1.length >= circleArr3.length ) {
						var mC:Array = circleArr1;
						var sC:Array = circleArr3;
					} else {
						var mC:Array = circleArr3;
						var sC:Array = circleArr1;
					}
				}
				
				for (var i:int = 0; i < PIXEL_NUM; i++) 
				{
					var point:Point;
					var ang:Number;
					
					if (mC.indexOf(i) == -1 && sC.indexOf(i) == -1) {
						var bi:int = bC.indexOf(i);
						point = Point.polar( bC.length / PIXEL_NUM * MAX_CIRCLE , ((360 / bC.length) * bi * Math.PI / 180));
						point.x -= MAX_RADIUS / 3;
						ang = (360 / bC.length) * bi;
					} else if (bC.indexOf(i) == -1 && sC.indexOf(i) == -1) {
						var mi:int = mC.indexOf(i);
						point = Point.polar( (mC.length+3) /PIXEL_NUM*MAX_CIRCLE , ((360 / mC.length) * mi * Math.PI / 180));
						point.x += MAX_RADIUS / 3;
						point.y += MAX_RADIUS / 3;
						ang = (360 / mC.length) * mi;
					} else if (bC.indexOf(i) == -1 && mC.indexOf(i) == -1) {
						var si:int = sC.indexOf(i);
						point = Point.polar( (sC.length+5) /PIXEL_NUM*MAX_CIRCLE , ((360 / sC.length) * si * Math.PI / 180));
						point.x += MAX_RADIUS / 2.5;
						point.y -= MAX_RADIUS / 3.5;
						ang = (360 / sC.length) * si;
					}
					dmyPixels[i] = [];				
					
					dmyPixels[i] = new DisplayObject3D();
					dmyPixels[i].x = point.x;
					dmyPixels[i].y = point.y;
					dmyPixels[i].rotationZ = ang;
					dmyObjs[0].addChild(dmyPixels[i]);
				}
				
			} else if ( _index == 3){										// 縦一直線
				for (var i:int = 0; i < PIXEL_NUM; i++) {
					dmyPixels[i] = [];
					
					dmyPixels[i] = new DisplayObject3D();
					dmyPixels[i].x = 0;
					dmyPixels[i].y = i * (PLANE_SIZE + PLANE_MARGIN) -((PLANE_SIZE+PLANE_MARGIN)*PIXEL_NUM)/2;
					dmyPixels[i].rotationZ = 0;	
					dmyObjs[0].addChild(dmyPixels[i]);
				}
			} else if ( _index == 4){										// 横一直線
				for (var i:int = 0; i < PIXEL_NUM; i++) {
					dmyPixels[i] = [];
					
					dmyPixels[i] = new DisplayObject3D();
					dmyPixels[i].x = i * (PLANE_SIZE + PLANE_MARGIN) -((PLANE_SIZE+PLANE_MARGIN)*PIXEL_NUM)/2;
					dmyPixels[i].y = 0;
					dmyPixels[i].rotationZ = 0;	
					dmyObjs[0].addChild(dmyPixels[i]);
				}
				
				
				
				
			} else if ( _index == 5){												// 最大円 重なりアリ
				for (var i:int = 0; i < PIXEL_NUM; i++) {
					dmyPixels[i] = [];				
					var point:Point = Point.polar( MAX_CIRCLE/2 , ((360 / PIXEL_NUM) * i * Math.PI / 180));
					
					dmyPixels[i] = new DisplayObject3D();
					dmyPixels[i].x = point.x;
					dmyPixels[i].y = point.y;
					dmyPixels[i].z = -100 - Math.random()*150;
					dmyPixels[i].rotationZ = (360 / PIXEL_NUM) * i;				
					dmyObjs[0].addChild(dmyPixels[i]);
				}
			}
			_index ++;
		}
		
        private function loop(e:TimerEvent = null):void 
		{
            // 各パーティクルに対してトゥイーンを設定
            for (var i:int = 0; i < PIXEL_NUM; i++) 
			{
				// パーティクル
				var p:DisplayObject3D = pixelArr[i];
				// ダミーオブジェクト
				var d:DisplayObject3D = dmyPixels[i];
				
				// BetweenAS3でトゥイーン
				BetweenAS3.delay(
					BetweenAS3.bezier(p,
						{
							x : d.sceneX,
							y : d.sceneY,
							z : d.sceneZ,
							rotationZ:d.rotationZ,
							rotationY  : 0
						},
						{ rotationY  : 360 }, getRandomPos(), 3 * Math.random() + 1, Quart.easeInOut
					),Math.random() * 0.5
				).play();				
            }
			
			//  ダミー生成
			dmySet();
        }
		
		private function getRandomPos():Object {
            return {
                x : MAX_RADIUS * (Math.random() - 0.5),
                y : MAX_RADIUS * (Math.random() - 0.5),
                z : MAX_RADIUS * (Math.random() - 2)
            };
        }
		
		private function clickHandler(e:InteractiveScene3DEvent):void {
			trace(e.currentTarget.x , e.currentTarget.y , e.currentTarget.z )
			e.target.alpha = 0.5;
			}
	}
}