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

C Curve

Get Adobe Flash player
by ton 18 Jan 2009
package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.Point;
    [SWF(backgroundColor=0x000000)]
    public class CCurve extends Sprite {
        private var list:Array = [];
        private const W:int = 465;
        private const H:int = 465;
        function CCurve() {
            var line:Line=new Line(new Point(W/4,H*2/3),new Point(W-W/4, H*2/3));
            list.push(line);
            stage.addChild(line);

            stage.addEventListener(Event.ENTER_FRAME,onEnterFrameHandler);
        }
        
        private function onEnterFrameHandler(event:Event):void {
            var line:Line=list[0];
            stage.removeChild(line);
            list.splice(0, 1);

            var p1:Point=new Point();
            p1.x= line.distance/2 * Math.SQRT2 * Math.cos(line.angle-Math.PI/4) + line.startP.x;
            p1.y= line.distance/2 * Math.SQRT2 * Math.sin(line.angle-Math.PI/4) + line.startP.y;

            var newLine:Line=new Line(line.startP,p1);
            stage.addChild(newLine);
            list.push(newLine);
            newLine=new Line(p1, line.endP);
            stage.addChild(newLine);
            list.push(newLine);
        }
    }
}

import flash.display.Sprite;
import flash.geom.Point;
class Line extends Sprite{
    public var startP:Point;
    public var endP:Point;
    public var distance:Number;
    public var angle:Number;
    function Line(startP:Point, endP:Point) {
        this.startP = startP;
        this.endP = endP;
        distance = Point.distance(startP, endP);
        angle = Math.atan2(endP.y-startP.y, endP.x-startP.x);
        
        graphics.lineStyle(0,0xffffff);
        graphics.moveTo(startP.x, startP.y);
        graphics.lineTo(endP.x, endP.y);
        graphics.endFill();
    }
}