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

CurveSample

see http://gihyo.jp/design/feature/01/frocessing/0003
Get Adobe Flash player
by nutsu 10 Aug 2009
/**
 * Copyright nutsu ( http://wonderfl.net/user/nutsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6NoY
 */

// see http://gihyo.jp/design/feature/01/frocessing/0003
package {
    import frocessing.display.F5MovieClip2D;
    [SWF(width=465,height=465,backgroundColor=0x000000)]
    public class CurveSample extends F5MovieClip2D
    {
        private var xs:Array;
        private var ys:Array;
        
        public function setup():void
        {
            rectMode(CENTER);
            stroke( 255 );
            noFill();
            xs = [];
            ys = [];
        }
        
        public function draw():void
        {
            if( isMousePressed ){
                xs.push( mouseX );
                ys.push( mouseY );
            }
            var i:int;
            var len:int = xs.length;
            for ( i = 0; i <len; i++ )
                rect( xs[i], ys[i], 3, 3 );
            
            //描画
            beginShape();
            if ( isKeyPressed ) {
                //直線で結ぶ
                for ( i = 0; i <len; i++ )
                    vertex( xs[i], ys[i] );
            } else {
                //スプライン曲線で結ぶ
                for ( i = 0; i <len; i++ )
                    curveVertex( xs[i], ys[i] );
            }
            endShape();
        }
        
        public function mousePressed():void
        {
            xs = [];
            ys = [];
        }
    }
}