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

練習 その11

Get Adobe Flash player
by hacker_d_xbu1sv 25 Apr 2009
    Embed
package {
    import flash.display.Sprite;
    import flash.geom.Point;
    import flash.events.TimerEvent;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.utils.Timer;
    import flash.geom.Point;
    import flash.ui.Mouse;

    
    public class FlashTest extends Sprite {
        private var ppt:Array;
        private var timer:Timer;
        
        public function FlashTest() {
            // write as3 code here..            
            ppt = new Array();
            
            for ( var i:Number = 0; i < 5; i++ )
            {
                ppt.push(new PhysicalPoint(0, 0));
            }
            
            timer = new Timer(33);
            timer.addEventListener(TimerEvent.TIMER, loop);
            timer.start();

        }

        private function loop(event:TimerEvent):void{
            for ( var i:Number = 0; i < ppt.length; i++ )
            {
                var par:Number = 8;
                if ( i == 0 )
                {
//                    ppt[i].setKasokudo((this.mouseX - ppt[i].x) * par,
//                                      (this.mouseY - ppt[i].y) * par);
                    ppt[0].x = this.mouseX;
                    ppt[0].y = this.mouseY;
                }
                else
                {
                    ppt[i].setKasokudo((ppt[i-1].x - ppt[i].x) * par,
                                        (ppt[i-1].y - ppt[i].y) * par);
                }
                
                
            }
            
            graphics.clear();
            drawCurve();
        }
        
        private function drawCurve():void{
            graphics.lineStyle(2, 0x00ff00);
            
            graphics.moveTo(ppt[0].x, ppt[0].y);
            graphics.curveTo(ppt[1].x, ppt[1].y, (ppt[2].x + ppt[1].x) / 2, (ppt[2].y + ppt[1].y) / 2);
            graphics.curveTo(ppt[2].x, ppt[2].y, (ppt[3].x + ppt[2].x) / 2, (ppt[3].y + ppt[2].y) / 2);
            graphics.curveTo(ppt[3].x, ppt[3].y,ppt[4].x, ppt[4].y);
            
            graphics.beginFill(0xff0000);
            graphics.lineStyle(0,0,0);
            for ( var i:Number = 0; i < ppt.length; i++ ){
                graphics.drawCircle(ppt[i].x, ppt[i].y, 2);
            }
        }
    }
}

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Point;
class PhysicalPoint extends Point{
    
    private var vx:Number, vy:Number;
    private var ax:Number, ay:Number;
    private var b:Number;
    private var sakkiTime:Number;
    private var timer:Timer;
    
    function PhysicalPoint(xx:Number = 0, yy:Number=0) 
    {
        x = xx;
        y = yy;
        b = 0.9;
        vx = 0;
        vy = 0;
        ax = 0;
        ay = 0;
        
        sakkiTime = new Date().getTime();
        
        timer = new Timer(33);
        timer.addEventListener(TimerEvent.TIMER, ptloop);
        timer.start();
    }
    
    private function ptloop(event:TimerEvent):void{
        var nowTime:Number = new Date().getTime();
        var t:Number = (nowTime -sakkiTime) / 1000;
        
        x += vx*t + 0.5*ax*t*t;
        y += vy*t + 0.5*ay*t*t;
        
        vx += ax*t;
        vy += ay*t;
        
        vx *= b;
        vy *= b;
        
        ax = 0;
        ay = 0;
        
        sakkiTime = nowTime;
    }
    
    public function setKasokudo(aax:Number=0, aay:Number=0):void{
        ax += aax;
        ay += aay;
    }
}