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

点3D forked from: [1日1Wonderfl]3D再び

/**
 * Copyright linktale ( http://wonderfl.net/user/linktale )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xVJC
 */

// forked from enok http://linktale.net/
// forked from yd_niku's forked from: forked from: [1日1Wonderfl]3D再び
// forked from yd_niku's forked from: [1日1Wonderfl]3D再び
// forked from yd_niku's [1日1Wonderfl]3D再び

package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    [SWF(backgroundColor=0xffffff, frameRate=60)]
    public class T3d extends Sprite {
        
        private var _camera:Camera;
        private var _renderList:Array = new Array();
        private var _particles:Array = new Array();
        private  var _clearList:Array = new Array();
        //private var _report:TextField;
        public function T3d() {
            //addChild( _report = new TextField );
            //_report.defaultTextFormat = new TextFormat( "_sans", 12, 0xFF3333 );
            //_report.text = "Start";
            
            _camera = new Camera();
            _camera.zoom = 0.5;
            _camera.fl= 500;
            //_camera.x= 0;
            _camera.y= -400;
            _camera.z= -100;
            _camera.rotateX= 60;
            
            const wlength:uint = 10;
            const hlength:uint = 10;
            const zlength:uint = 10;
            const intervalX:uint = 100;
            const intervalY:uint = 100;
            const intervalZ:uint = 100;
            for( var i:int = 0; i< wlength; ++i ) {
                for ( var j:int = 0; j < hlength; ++j ) {
                    for( var k:int = 0; k< zlength; ++k ) {
                        var ball:Ball = new Ball( ( i - wlength*0.5 ) * intervalX, -k * intervalZ, ( j - hlength*0.5 ) * intervalY, 10, 0xFF000000 );
                        addCastChild( ball );
                    }
                }
            }
            //ball= new Ball( 0, 0, 0, 3, 0xFFFFFFFF );
            //addCastChild( ball );
            addEventListener( Event.ENTER_FRAME, update );
            
            //Wonderfl.disable_capture();
            //Wonderfl.capture_delay( 10 );
            
            G.x = 0;
            G.y = 0.08;
            G.z = 0;
            WIND.x = -0.08;
            WIND.y = 0.01;
            WIND.z = 0.10;
        }
        public function addCastChild( cast:DisplayCast ):DisplayCast {
            addChild( cast.view );
            _renderList.push( cast );
            return cast;
        }
        public function removeCastChild( cast:DisplayCast ):DisplayCast {
            removeChild( cast.view );
            var i:int = _renderList.indexOf( cast );
            _renderList.splice(i,1);
            return cast;
        }
        
        private function emitter():void {
            for( var i:int=0; i<20; ++i ) {
                var p:Particle = addCastChild(
                    new Particle( Math.random()*100-50, Math.random()*100-50, 0, Math.random()*20+1, 0xFFFF5555 )
                ) as Particle;
                p.vx = Math.random()*30-15;
                p.vy = -40 * Math.random() - 20;
                p.vz = Math.random()*30-15;
                _particles.push(p);
            }
            //_report.text = String(_particles.length);
        }
        private const G:Object = new Object();
        
        private const FRICTION:Number = 0.98;
        private const WIND:Object= new Object();
        private function calcurate():void {
            _camera.rotateX +=  (( 360 * (mouseY - CENTER.y) / 435 + 0 ) - _camera.rotateX  )* 0.05 ;
            _camera.rotateY +=  (( 360 * (mouseX - CENTER.x) / 435 ) - _camera.rotateY ) * 0.03;
            

            /*
            for each( var p :Particle in _particles ) {
                
                if( p.life <= 0 ) {
                    _clearList.push(p);
                    continue;
                }
                p.vx *=FRICTION;
                p.vy *=FRICTION;
                p.vz *=FRICTION;
                p.vx +=G.x + WIND.x;
                p.vy +=G.y + WIND.y;
                p.vz +=G.z + WIND.z;
                p.x  += p.vx;
                p.y  += p.vy;
                p.z  += p.vz;
                p.life--;
            }
            while( (p=_clearList.shift())!=null ){
                removeCastChild( p );
                var i:int = _particles.indexOf( p );
                _particles .splice(i,1);
            }
            */
        }
        private function changeWind():void {
            WIND.x += ( Math.random()-0.5 ) * 0.03;
            WIND.y += ( Math.random()-0.5 ) * 0.03;
            WIND.z += ( Math.random()-0.5 ) * 0.03;
        }
        
        private const CENTER:Point = new Point(220,220);
        private var emitterCount:int = 0;
        private var windCount:int = 0;
        private function update(e:Event):void {
            //if( emitterCount++ % 10 == 0 ) emitter();
            if( windCount++ % 40 == 0   ) changeWind();
            calcurate();
            for each( var cast:DisplayCast in _renderList ) {
                renderCast( cast );
            }
        }
        private function renderCast( cast:DisplayCast ):void {
            var radX:Number = Math.PI*_camera.rotateX/180;
            var radY:Number = Math.PI*_camera.rotateY/180;
            var radZ:Number = Math.PI*_camera.rotateZ/180;
            
            var diffX:Number = (cast.x - _camera.x)*_camera.zoom;
            var diffY:Number = (cast.y - _camera.y)*_camera.zoom;
            var diffZ:Number = (cast.z - _camera.z)*_camera.zoom;
            
            var rotZdiffX:Number = diffX*Math.cos(radZ) - diffY*Math.sin(radZ);
            var rotZdiffY:Number = diffX*Math.sin(radZ) + diffY*Math.cos(radZ);
            
            diffX= rotZdiffX;
            diffY= rotZdiffY;
            
            var rotXdiffY:Number = diffY*Math.cos(radX) - diffZ*Math.sin(radX);
            var rotXdiffZ:Number = diffY*Math.sin(radX) + diffZ*Math.cos(radX);
            
            //diffY= rotXdiffY;
            diffZ= rotXdiffZ;
            
            var rotYdiffZ:Number = diffZ*Math.cos(radY) - diffX*Math.sin(radY);
            var rotYdiffX:Number = diffZ*Math.sin(radY) + diffX*Math.cos(radY);
            
            diffZ= rotYdiffZ;
            //diffX= rotYdiffX;
            
            var persepective :Number =_camera.fl / (_camera.fl + diffZ);
            cast.view.x = diffX * persepective + CENTER.x;
            cast.view.y = diffY * persepective + CENTER.y;
            
            cast.view.scaleX = cast.view.scaleY = Math.max( 0.0, persepective*_camera.zoom );
            cast.view.alpha = Math.min( 1, cast.view.scaleX+0.6 )
        }
    }
}



import flash.display.*;
import flash.filters.*;

internal class Cast {
    public var x:Number = 0;
    public var y:Number = 0;
    public var z:Number = 0;
    public var rotateX:Number = 0;
    public var rotateY:Number = 0;
    public var rotateZ:Number = 0;
    public function Cast( x:Number = 0, y:Number =0, z:Number =0 ){
        this.x = x;
        this.y = y;
        this.z = z;    
    }
}

internal class DisplayCast extends Cast {
    public var view:DisplayObject;
    public function DisplayCast( view:DisplayObject, x:Number = 0, y:Number =0, z:Number =0 ) {
        super( x, y, z );
        this.view =  view;
    }
}
internal class Camera extends Cast {
    public var fl:Number = 500;
    public var zoom:Number = 1.0;
    public function Camera( x:Number = 0, y:Number =0, z:Number =-300 ) {
        super( x, y, z );
    }
}

internal class BallView extends Sprite {
    private static const blur:BlurFilter = new BlurFilter();
    public function BallView( r:Number = 10.0, color:uint = 0xFFcc0000 ) {
        super();
        graphics.beginFill( color & 0xFFFFFF, color >> 24 & 0xFF );
        graphics.drawCircle( 0, 0, r );
        graphics.endFill();
        //blendMode = BlendMode.SCREEN;
        //filters = [blur];
    }
}
internal class Ball extends DisplayCast {
    public function Ball( x:Number = 0, y:Number =0, z:Number =0, r:Number = 10.0, color:uint = 0xFFcc0000 ) {
        super( new BallView( r, color ), x, y, z );
    }
}


internal class Particle extends Ball {
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var vz:Number = 0;
    public var life:int= Math.random()*100 + 100;
    
    public function Particle ( x:Number = 0, y:Number =0, z:Number =0, r:Number = 10.0, color:uint = 0xFFcc0000 ) {
        super( x, y, z, r, color );
    }
}