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: 3D演習その1

ActionScript3.0Animation読みながら、とりあえず3D投影してみる。
Get Adobe Flash player
by hiro_loveness 11 May 2015
// forked from yd_niku's 3D演習その1
package {
    //ActionScript3.0Animation読みながら、とりあえず3D投影してみる。
    import flash.display.Sprite;
    import flash.events.Event;
    public class FlashTest extends Sprite {
        private var renderList:Array = [];
        private var screenX:Number;
        private var screenY:Number;
        public function FlashTest() {
            screenX = stage.stageWidth/2;
            screenY = stage.stageHeight/2;
            setup();
            addEventListener( Event.ENTER_FRAME, render );
        }
        private function setup():void {
            var xNum:uint = 8;
            var yNum:uint = 8;
            var zNum:uint = 10;

            var xInterval:uint = 50;
            var yInterval:uint = 50;
            var zInterval:uint = 50;
            for( var i:int=0; i<xNum; ++i ) {
                for( var j:int=0; j<yNum; ++j ) {
                    for( var k:int=0; k<zNum; ++k ) {
                        createBall(
                            (i-xNum*0.5)*xInterval,
                            (j-yNum*0.5)*yInterval,
                            (k-zNum*0.2)*zInterval
                        );
                    }
                }
            }
        }
        private function createBall( sx:Number, sy:Number, sz:Number ):void {
            var sp :Sprite = new Sprite();
            sp.graphics.lineStyle(0,0xffffff);
            sp.graphics.beginFill(0xcc6600);
            sp.graphics.drawCircle( 0, 0, 10 );
            sp.graphics.endFill();
            addChild( sp );
            trace(sx);
            renderList.push( {
                x: sx,
                y: sy,
                z: sz,
                view:sp
            });
        }
        private var focus:uint = 250;
        private function render(e:Event):void {
            renderList.sortOn( "z", Array.DESCENDING|Array.NUMERIC );
            var l:uint = renderList.length;
            for( var i:uint=0; i<l; ++i ) {
                var obj:Object = renderList[i];
//                if( obj.z > -focus ) {
                    var scale :Number= focus/(focus+obj.z);
                    obj.view.x = screenX + obj.x * scale;
                    obj.view.y = screenY + obj.y * scale;
                    obj.view.scaleX = obj.view.scaleY = scale;
                    obj.view.alpha = Math.min( 1, scale );
                    obj.view.visible = true;
                    this.setChildIndex( obj.view, i );
                    /*
                }
                else {
                    obj.view.visible = false;
                }
                */
            }
        }
    }
}