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

ND3d v2

前作からちょっと変更した。
Get Adobe Flash player
by nulldesign 19 May 2011
    Embed
/**
 * Copyright nulldesign ( http://wonderfl.net/user/nulldesign )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6JBp
 */

/*
気が向いたからアップデートなう。
102行目から104行目当たりをコメントアウトしたら違う感じになる。はず
*/
package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.GlowFilter;
    import flash.filters.BlurFilter;

    public class idxnd3d extends Sprite
    {
        private var _world:ND3d;

        public function idxnd3d():void
        {
            // constructor code
            loaderInfo.addEventListener( IOErrorEvent.IO_ERROR, _onioerror );
            addEventListener( Event.ADDED_TO_STAGE, init );
        }
        
        private function init ( e:Event ):void
        {
            loaderInfo.removeEventListener( IOErrorEvent.IO_ERROR, _onioerror );
            removeEventListener( Event.ADDED_TO_STAGE, init );
            
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.HIGH;
            stage.showDefaultContextMenu = false;
            this.tabEnabled = false;
            
            initialize();
            _world.renderStart();
            
        }
        
        private var _list:Array = [];
        private function initialize():void
        {
            this.graphics.beginFill(0);
            this.graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
            this.graphics.endFill();    
            
            var _screen:Sprite = new Sprite();
            addChild( _screen );
            _screen.x = int( stage.stageWidth * .5 );
            _screen.y = int( stage.stageHeight * .5 );
            _world = new ND3d( _screen );
            
            stage.addEventListener( Event.RESIZE, function()
                                   {
                                        _screen.x = int( stage.stageWidth * .5 );
                                        _screen.y = int( stage.stageHeight * .5 );
                                   }
                                   );
            
            for( var i:int = 0; i < 120; i++ )
            {
                var _h:ND3DObject = new ND3DObject();
                _h.graphics.beginFill( 0xFFFFFF );
                _h.graphics.drawCircle( 0, 0, 10 );
                _h.filters = [ new GlowFilter( Math.random() * 0xFFFFFF, 1, 8, 8, 2, 1 ), new BlurFilter( 4, 4, 3 ) ];
                _h.blendMode = BlendMode.SCREEN;
                _world.addChild( _h );
                
                var R:int = 12;
                var _rad:Number = i * 3 * Math.PI / 180;
                _h.vx = Math.cos( _rad ) * R;
                _h.vz = Math.sin( _rad ) * R;
                
                _h.vx = _h.vz = 0;
                /*
                _h.x = Math.cos( _rad * 5 ) * i * 5;
                _h.y = Math.sin( _rad  * 3 ) * 100;
                _h.z = Math.sin( _rad * 5 ) * i * 5;
                */
                _h.x = Math.cos( _rad * 5 + i / 100 ) * i * 3;
                _h.y = Math.sin( _rad * 4 ) * 240;
                _h.z = Math.sin( _rad * 5 + i / 100 ) * i * 3;
                
                _list.push( _h );
            }
            
            addEventListener( Event.ENTER_FRAME, _loop );
        }
        
        private var _count:int = 0;
        private function _loop( e:Event ):void
        {
            var _sin:Number = Math.sin( .01 );
            var _cos:Number = Math.cos( .01 );
            var len:int = _list.length;
            _count++;
            while( len )
            {
                len--;
                var _h:ND3DObject = ND3DObject( _list[len] );
                //_h.vx += Math.random() * .2 - .1;
                //_h.vz += Math.random() * .2 - .1;
                
                _h.vx = ( _h.vx + ( 0 - _h.x ) / ( 50 + len * 16 ) ) / 1.000;
                _h.vy = ( _h.vy + ( 0 - _h.y ) / ( 50 + len * 12 ) ) / 1.000;
                _h.vz = ( _h.vz + ( 0 - _h.z ) / ( 50 + len * 8 ) ) / 1.000;
                
                //    _h.vx *= 0.96;
                //    _h.vy *= 0.96;
                //    _h.vz *= 0.96;
                
                _h.x += _h.vx;
                _h.y += _h.vy;
                _h.z += _h.vz;
                
                _h.x = _h.x * _cos - _h.z * _sin;
                _h.z = _h.x * _sin + _h.z * _cos;
            }
            
            ND3d.cameraY += 0.01;
        }
        
        private function _onioerror( e:Event ):void{}

    }

}


    import flash.display.DisplayObject;
    import flash.display.DisplayObjectContainer;
    import flash.events.Event;

    class ND3d
    {
        public static var distance:Number = 300;
        public static var focus:Number = 500;
        public static var cameraY:Number = 0;
        
        private var _objList:Array = [];
        
        private var _stage:DisplayObjectContainer;

        public function ND3d( e:DisplayObjectContainer ):void
        {
            // constructor code
            _stage = e;
        }
        
        public function addChild( e:ND3DObject ):void
        {
            _stage.addChild( e );
            _objList.push( e );
        }
        
        public function removeChild( e:DisplayObject ):void
        {
            _stage.removeChild( e );
        }
        
        public function set x( e:Number ):void    {    _stage.x = e;        }
        public function get x():Number            {    return _stage.x;    }
        public function set y( e:Number ):void    {    _stage.y = e;        }
        public function get y():Number            {    return _stage.y;    }
        
        
        
        
        public function renderStart():void
        {
            _stage.addEventListener( Event.ENTER_FRAME, _loop );
        }
        public function renderStop():void
        {
            _stage.removeEventListener( Event.ENTER_FRAME, _loop );
        }
        
        private function _loop( e:Event ):void
        {
            update();
        }
        
        public function update():void
        {
            var len:int = _objList.length;
            moveType00( len );
            
            //    Z sort
            _objList.sortOn( "_y", Array.DESCENDING | Array.NUMERIC );
            
            
            var _hw:int = int( _stage.stage.stageWidth * .5 );
            var _hh:int = int( _stage.stage.stageHeight * .5 );
            while( len )
            {
                //    view check
                len--;
                var _obj:ND3DObject = ND3DObject( _objList[len] );
                _obj = ND3DObject( _objList[len] );
                _stage.addChild( _obj );
                
                _obj.visible = true;
                if( _obj._x < -_hw || _obj._x > _hw ) _obj.visible = false;
                if( _obj._y < -_hh || _obj._y > _hh ) _obj.visible = false;
                if( _obj.scale < .02 ) _obj.visible = false;
                if( focus + distance + _obj.z <= focus * .25 )
                {
                    _obj.visible = false;
                    _obj.scale = 0;
                }
            }
        }
        
        private function moveType00( e:int ):void
        {
            var len:int = e;
            var _vc:Number = Math.cos( Math.PI / 6 * 5  * 2) * Math.sin( cameraY );
            
            while( len )
            {
                len--;
                var _obj:ND3DObject = ND3DObject( _objList[len] );
                var _scaleRatio:Number = focus / ( focus + ( _obj.z + distance ));
    
                _obj.visible = true;
                _obj._x = _obj.x * _scaleRatio;
                _obj._y = ( _obj.y - _obj.z * _vc ) * _scaleRatio;
                _obj.scale = _scaleRatio;
            }
        }

    }
   
    
    
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.events.Event;

    class ND3DObject extends Sprite
    {
        public var __x:Number = 0;
        public var __y:Number = 0;
        public var __z:Number = 0;
        public var vx:Number = 0;
        public var vy:Number = 0;
        public var vz:Number = 0;

        public function ND3DObject():void
        {
            // constructor code
            addEventListener( Event.ADDED_TO_STAGE, init );
        }
        
        public function init( e:Event ):void
        {
            removeEventListener( Event.ADDED_TO_STAGE, init );
            addEventListener( Event.REMOVED_FROM_STAGE, remove );
        }
        
        override public function get x():Number            {    return __x;    }
        override public function set x( e:Number):void    {    __x = e;    }
        override public function get y():Number            {    return __y;    }
        override public function set y( e:Number):void    {    __y = e;    }
        override public function get z():Number            {    return __z;    }
        override public function set z( e:Number):void    {    __z = e;    }
        
        public function get _x():Number            {    return super.x    };
        public function set _x( e:Number ):void    {    super.x = e;    };
        public function get _y():Number            {    return super.y    };
        public function set _y( e:Number ):void    {    super.y = e;    };
        public function get _z():Number            {    return super.z    };
        public function set _z( e:Number ):void    {    super.z = e;    };
        
        public function set scale( e:Number ):void
        {
            this.scaleX = this.scaleY = e;
        }
        
        public function get scale():Number
        {
            return this.scaleX;
        }
        
        
        public function remove( e:Event ):void
        {
            removeEventListener( Event.ADDED_TO_STAGE, init );
            addEventListener( Event.REMOVED_FROM_STAGE, remove );
            
            var len:int = this.numChildren;
            while( len )
            {
                len--;
                var _obj = removeChild( this.getChildAt( len ) );
                if( _obj is Bitmap )    _obj.dispose();
                if( _obj is Loader )    _obj.unload();
                
                //
                _obj = null;
            }
        }

    }