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

curveToで道を進んでる感じ

@author itoz (http://www.romatica.com)
*    チカラ技
*    いちおうマウスにも反応するよ!
*    JS DO IT でも同じことしたいな!
*
*    [追記] JS SO IT でも作った。
*    http://jsdo.it/itoz/m0Mu
Get Adobe Flash player
by romatica 05 Aug 2010
/**
 * Copyright romatica ( http://wonderfl.net/user/romatica )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/a7OA
 */

/**
 *
 *    @author itoz (http://www.romatica.com)
 *    チカラ技
 *    いちおうマウスにも反応するよ!
 *    JS DO IT でも同じことしたいな!
 *
 *    [追記] JS SO IT でも作った。
 *    http://jsdo.it/itoz/m0Mu
 */
package  
{
    import flash.display.GradientType;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.geom.Matrix;
    import flash.utils.Timer;

    /**
     * 
     */
    [SWF(backgroundColor="#FFFFFF", frameRate="40", width="468", height="468")]
    public class Road3D extends Sprite 
    {
        private var debug:Boolean = false;
        private const startY:Number = 100;
        private const startZ:Number = 2500;
        private const spd:Number = 200;
        //
        private var _vpX:int;
        private var _vpY:int;
        private var _fl:Number;
        //point
        private var makeTimer:Timer;
        private var pointStart:SimpleObject3D;
        private var poinObjArr:Array;
        private var mouseTrg:Sprite;
        private var figureEight:FigureEight;
        //gradient
        private var gradType:String = GradientType.LINEAR;
        private var gradArr:Array = [ 0xdae1a2, 0xffffff ];
        private var alphaArr:Array = [ 1, 1 ];
        private var ratioArr:Array = [ 0, 230 ];
        private var mtr:Matrix = new Matrix( );
        private var canvas:Sprite;
        private var sky:Sprite;
                private var horizon:Sprite;
        public function Road3D()
        {
            _vpX = 468 / 2;
            _vpY = 468 / 2 - 150;
            _fl = 10500;
            poinObjArr = [];
            mtr.createGradientBox( 468 , 468 , Math.PI /2 , 0 ,-320 );
            
            sky = addChild(new Sprite()) as Sprite;
            sky.y-20;
            sky.graphics.beginGradientFill( gradType , gradArr , alphaArr , ratioArr,mtr  );
            sky.graphics.drawRect(0, 0, 468, 200);
            sky.graphics.endFill();
            
                        horizon = addChild(new Sprite()) as Sprite;
            horizon.y=163;
            horizon.graphics.beginGradientFill( gradType , gradArr , alphaArr , ratioArr,mtr  );
            horizon.graphics.drawRect(0, 0, 468, 200);
            horizon.graphics.endFill();
            
            canvas = addChild(new Sprite()) as Sprite;
            
            
            mtr.createGradientBox( 468 , 468 , Math.PI / 2 , 0 , 50 );
            createMouseTarget( );
            createStartPoint( );
            
            pointMakeStart( );
            addEventListener( Event.ENTER_FRAME , update );
        }

        private function createMouseTarget():void 
        {
            mouseTrg = addChild( new Sprite( ) ) as Sprite;
            figureEight = new FigureEight( 100 , 4 , 0 );
            mouseTrg.addChild( figureEight );
            
        }

        private function createStartPoint():void 
        {
            pointStart = new SimpleObject3D( 0 , startY , startZ + 200 , 0 );
            
        }

        private function pointMakeStart():void 
        {
            
            makeTimer = new Timer( 50 , 0 );
            makeTimer.addEventListener( TimerEvent.TIMER , makePointTimer );
            makeTimer.start( );
        }

        private function makePointTimer(e:TimerEvent):void 
        {
            var _xx:Number = pointStart.xx;
            var _yy:Number = startY;
            var _zz:Number = startZ;
            var _speed:Number = spd;
            makePoint( _xx , _yy , _zz , _speed , 2 );
        }

        private function makePoint(_xx:Number,_yy:Number,_zz:Number,_speed:Number,span:Number = 0):void
        {
            //pntL
            var pointL:SimpleObject3D = new SimpleObject3D( _xx - span , _yy , _zz , _speed );
            
            //pntR
            var pointR:SimpleObject3D = new SimpleObject3D( _xx + span , _yy , _zz , _speed );
            
            poinObjArr.push( {"L":pointL , "R":pointR} );
        }

        private function move(trg:SimpleObject3D):void
        {
            trg.scale = _fl / (_fl + trg.zz);
            trg.x = _vpX + trg.xx * trg.scale;
            trg.y = _vpY + trg.yy * trg.scale;
            trg.scaleX = trg.scaleY = trg.scale * 1.1;
        }

        protected function update(e:Event):void 
        {
            //------------------------------------
            //ターゲットとスタートポイント
            var mx:Number = (this.mouseX < 0) ? 0 : this.mouseX;
            
            mouseTrg.x += (mx - mouseTrg.x ) * 0.05;
            pointStart.xx = ((mouseTrg.x + figureEight.x) - _vpX) * 0.2;
            var startPointScale:Number = _fl / (_fl + pointStart.zz);
            pointStart.x = _vpX + pointStart.xx * startPointScale;
            pointStart.y = _vpY + pointStart.yy * startPointScale;
            
            //------------------------------------
            // 頂点移動
            for (var n:int = 0; n < poinObjArr.length; n++) {
                var pntL:SimpleObject3D = poinObjArr[n]["L"];
                var pntR:SimpleObject3D = poinObjArr[n]["R"];
                //trace(pntL.zz)
                pntL.xx -= 0.5;
                pntR.xx += 0.5;
                pntL.zz -= pntL.spd;
                pntR.zz -= pntR.spd;
                
                if (pntL.zz <= -_fl) {
                    
                    poinObjArr[n] = null;
                    poinObjArr.shift( );
                    pntL = null;
                    pntR = null;
                } else {
                    move( pntL );
                    move( pntR );
                }
            }
            
            //----------------------------------------------------------
            // ライン引く
            canvas.graphics.clear( );
            canvas.graphics.beginGradientFill( gradType , gradArr , alphaArr , ratioArr , mtr );
            //----------------------------------------------------------
            //   左ライン
                        var maxL:int =poinObjArr.length;
            for (var i:int = 0; i < maxL; i++) {
                
                var pntL2:SimpleObject3D = poinObjArr[i]["L"];
                var nextPntL:SimpleObject3D;
                var spanX:Number;
                var spanY:Number;
                

                if(i == 0) {
                    //最初のポイントなら
                    canvas.graphics.moveTo( poinObjArr[i]["L"].x , poinObjArr[i]["L"] .y );
                }else if(i == poinObjArr.length - 1) {
                    //最後のポイントなら
                    nextPntL = pointStart;
                    spanX = pntL2.x + (nextPntL.x - pntL2.x ) / 2;
                    spanY = pntL2.y + ( nextPntL.y - pntL2.y ) / 2;
                    canvas.graphics.curveTo( nextPntL.x , nextPntL.y , spanX , spanY );
                } else {
                    nextPntL = poinObjArr[i + 1]["L"];
                    spanX = pntL2.x + (nextPntL.x - pntL2.x ) / 2;
                    spanY = pntL2.y + ( nextPntL.y - pntL2.y ) / 2;
                    canvas.graphics.curveTo( pntL2.x , pntL2.y , spanX , spanY );
                }
            }
            
            //----------------------------------------------------------
            //   右ライン
            var rMax:int = poinObjArr.length - 1;
            if(rMax==-1) return;
            while(rMax--) {
                var pntR2:SimpleObject3D = poinObjArr[rMax]["R"];
                var nextPntR:SimpleObject3D;
                var spanRX:Number;
                var spanRY:Number;
                if(rMax == 0) {
                    canvas.graphics.moveTo( poinObjArr[0]["L"].x , poinObjArr[0]["L"].y );
                } else {
                    nextPntR = poinObjArr[rMax - 1]["R"];
                    spanRX = pntR2.x + (nextPntR.x - pntR2.x) / 2;
                    spanRY = pntR2.y + (nextPntR.y - pntR2.y) / 2;
                    canvas.graphics.curveTo( pntR2.x , pntR2.y , spanRX , spanRY );
                }
            }
            canvas.graphics.endFill( );
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;


class SimpleObject3D extends Sprite  
{
    public var xx:Number;
    public var yy:Number;
    public var zz:Number;
    public var scale:Number;
    public var spd:Number;

    public function SimpleObject3D(_xx:Number = 0,_yy:Number = 0,_zz:Number = 0,_spd:Number = 0)
    {
        xx = _xx;
        yy = _yy;
        zz = _zz;
        spd = _spd;
    }
}


class FigureEight extends Sprite
{
    private var r:Number;
    private var spd:Number;
    private var ang:Number;

    public function FigureEight(_r:Number,_spd:Number,_ang:Number) 
    {
        r = _r;
        spd = _spd;
        ang = _ang;
        addEventListener( Event.ENTER_FRAME , update );
    }

    private function update(event:Event):void 
    {
        if (ang >= 360) ang = 360 - ang;
        var rad:Number = ang * Math.PI / 180;
        x = Math.sin( rad ) * r;
        y = Math.sin( rad * 2 ) * r / 2;
        ang += spd;
    }
}