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

[練習中]

昔やった遊び
Get Adobe Flash player
by Tamanegi_kenshi 06 Sep 2010
    Embed
/**
 * Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jinx
 */

//昔やった遊び

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;
    import flash.display.Bitmap;
    import flash.display.BitmapData;   

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.BitmapFileMaterial;
    import org.papervision3d.objects.*;

    import flash.system.Security;
    
    import caurina.transitions.Tweener;


    public class Test extends Sprite{
        //papervison3Dの変数を定義
        private var camera:Camera3D = new Camera3D();
        private var scene:Scene3D = new Scene3D();
        private var viewport:Viewport3D = new Viewport3D(550, 400);
        private var renderer:BasicRenderEngine = new BasicRenderEngine();

        private var angle:int = 0;
        private var angleX:Number = 0;

        private var va:Number = 1;
        
        //bitmapの変数を定義
        private var bd:BitmapData;
        private var bt:Bitmap;
        

        //plnaeの設定
        private var  planeArr0:Array = [];
        private var  planeArr1:Array = [];
        private var  planeNum:int =4;
        private var  planeWArr:Array = [150,50,50,50];
        private var  planeW:int = 50;
        private var  plaenH:int = 400;
        
        
        
        //fileの変数を定義
        private var file0:String = "http://assets.wonderfl.net/images/related_images/a/a4/a4d1/a4d19c4be48d01b87d18a112ee7cbfc7b1402225";
        private var file1:String = "http://assets.wonderfl.net/images/related_images/b/b6/b6fd/b6fd806fd6f3261ec9af0332f38ba36c1850a4ce";
        private var file2:String = "http://assets.wonderfl.net/images/related_images/8/8d/8de6/8de6ac2f61f0b86c24f9b8eba401d743d3c14d81";
        private var file3:String = "http://assets.wonderfl.net/images/related_images/e/e7/e785/e7853a0c75962c8a6a3b2061f04907296966f012";
        private var fileArr:Array = [file0, file1, file2, file3];
        
        private var rootNode:DisplayObject3D;
        private var rootNode2:DisplayObject3D;
        
        //折れているか
        private var isOri:Boolean = false;
        
        //Tweenerしているか
        private var isTween:Boolean = true;

    public function Test(){
        init();
    }

    private function init():void{
        //fileの読み込み
        Security.allowDomain("assets.wonderfl.net");
        Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
     
     //マウスをステージから消す      
        Mouse.hide();
        
        
        //papervision3Dの設定
        camera.z = -500;
        addChild(viewport);
       
       
        
        rootNode = new DisplayObject3D();
        scene.addChild(rootNode);
       

        //板(plane)をplaneNum個作る
        for(var i:int = 0; i < planeNum; i++){

        //BitmapFileMaterialで画像を読み込む
        var material:BitmapFileMaterial = new BitmapFileMaterial(fileArr[i]);

        //ColorMaterialで色を設定する
        //var material:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff);

        //板に色をつけるときのmaterial(今回は使わない)
        //var material:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff);

        //materialの裏側を表示する
        material.doubleSided  = true;

        //板(plan)を作成する
        var plane:Plane = new Plane(material, planeW, plaenH);

        //sceneにplaneを表示する
        rootNode.addChild(plane);

        //planeの配列planeArrにplaneを入れる
        planeArr0.push(plane);
        
        }
        
        //rootNodeのy位置を-600に設定する
        rootNode.y = -600;
        
        //y位置0にdelay:2後,time:1で移動し、終了後を実行する
        Tweener.addTween(rootNode,{y:0, delay:2, time:1, onComplete:finTween});
        
        function finTween():void{
            isTween = false;
        }

        
      
 

        //ステージとonClickを関連付ける
        stage.addEventListener(MouseEvent.CLICK, onClick);
        
        //ステージとonEnterを関連付ける
        stage.addEventListener(Event.ENTER_FRAME, onEnter);


        /*
        var material2:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff);
        material2.doubleSided  = true;
        var plane2:Plane = new Plane(material2, 100, 100);

        var material3:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff);
        material3.doubleSided  = true;
        var plane3:Plane = new Plane(material3, 100, 100);


        scene.addChild(plane2);
        scene.addChild(plane3);
        */
        }




    //折れている
    private function onClick(e:MouseEvent):void{
        
        //もし、isOriが真なら
        if(isOri == true){
           
            //isOriを偽にする
            isOri = false;
        
        //それ以外なら    
        }else{
            
            //isOriを真にする
            isOri = true;
        }
    }


    //角度を設定するfunction onOriをつくる
    private function onOri():void{
        
        //angleを変数vaづつ増やす
        angle += va;
        
        //もし、anngleが90以上か-90以下なら
        if(angle >= 90 || angle <= -90){
        
        //変数vaに-1をかける
        va *= -1;
        }
    }
    
    //並びを設定するfunction setOriをつくる
    private function setOri():void{
        
        //角度をラジアンに変える
        var radian:Number = angle * Math.PI / 180;
        
        //planeNumの回数繰り返す
        for(var i:int = 0; i < planeNum; i++){
        
        //コサインで底辺の長さx1を求める
        var x1:Number = Math.cos(radian) *  planeW;
        
        //var z1:Number = Math.sin(radian) * 100;

        //planの位置を設定する
        //rootNodeをステージ真ん中に配置するために,(底辺の長さの半分をplaneNumから1を引いた数でかけてマイナスにす)
        // + 底辺の長さとplaneNumの数をかける
        planeArr0[i].x = (-x1 /2 * planeNum - 1) + x1 * i;
        
        //もし、iが2で割り切れる場合
        if(i % 2 == 0){
        
            //planeの角度はそのまま
            planeArr0[i].rotationY = angle;
        
        //それ以外(2で割り切らない場合)
        }else{
        
            //planeの角度は反対にする
            planeArr0[i].rotationY = -angle;
        }//if
        }///for i
    }//setOri

    

    private function onEnter(e:Event):void{
        
        //setOriを実行する
        setOri();
        
        //もし、isOriが真なら
        if(isOri == true){
        
            //onOriを実行する
            onOri();
        }
        
        //もし,Tweenが終了していたら
        if(isTween == false){
           
           
           rootNode.rotationX = (232 - mouseY) * 0.4;
           
           camera.x =(232 - mouseX) * 0.5;
        }


        //plane.rotationY = angle;
        //plane2.rotationY = -angle;
        //plane3.rotationY = angle;

/*
        var radian:Number = angle * Math.PI / 180;
        for(var i:int = 0; i < planeNum; i++){
        var x1:Number = Math.cos(radian) *  planeW;
        //var z1:Number = Math.sin(radian) * 100;


        planeArr0[i].x = -x1 /2 * planeNum - 1 + x1 * i;
        if(i % 2 == 0){
        planeArr0[i].rotationY = angle;
        }else{
        planeArr0[i].rotationY = -angle;
        }
    }

    
*/
        //plane2.x = -x1 / 2 + x1;
        //plane3.x = -x1 / 2 + x1 * 2;
    
    /*
        angleX = (232 - mouseY) * 0.5;

        var radi:Number =  angleX * Math.PI / 180;
        camera.z = -500 * Math.cos(radi);
        camera.y = 500 * Math.sin(radi);

        var dy:Number = 0 - camera.y;
        var dz:Number = 0 - camera.z;
        var ang:Number = Math.atan2(dy, dz);
        camera.rotationX = -ang * 180 / Math.PI;
        */
        
        

        renderer.renderScene(scene, camera, viewport);
        }


    }
}