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

ドラゴン曲線

Get Adobe Flash player
by ton 24 Dec 2008
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    
    [SWF(frameRate=60, backgroundColor=0x000000)]
    public class DoragonCurve extends Sprite {
	private var list:Array = [];
	private const W:int = stage.stageWidth;
	private const H:int = stage.stageHeight;

	function DoragonCurve() {

	    addLine(new Point(W/5, H/2), new Point(W-W/5, H/2));
	    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;
	    addLine(line.endP, p1);
	    addLine(line.startP, p1);
	}

	private function addLine(p1:Point, p2:Point):void{
	    var line:Line = new Line(p1, p2);
	    stage.addChild(line);
	    list.push(line);
	}
    }
}

import flash.display.Shape;
import flash.geom.Point;

class Line extends Shape{
    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();
    }
}