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

flash on 2011-4-17

Get Adobe Flash player
by kihon 17 Apr 2011
    Embed
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import frocessing.color.ColorHSV;
 
    public class Main extends Sprite
    {
        private var t:Number = 1.0;
        private var points/*Point*/:Array = [new Point(10, 440), new Point(20, 30), new Point(350, 80), new Point(300, 400), new Point(450, 40)];
        private var canvas:Sprite;
        
        public function Main()
        {
            addChild(canvas = new Sprite());
            
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(event:Event):void 
        {
            if (t > 1.0)
            {
                t = 0.0;
                canvas.graphics.clear();
                canvas.graphics.lineStyle(3.0);
                canvas.graphics.moveTo(points[0].x, points[0].y);
            }
            
            bezierCurve();
            t += 0.002;
        }
        
        private function bezierCurve():void
        {
            graphics.clear();
            var src/*Point*/:Array;
            var dest/*Point*/:Array = [];
            var color:ColorHSV = new ColorHSV();
            src = points.slice();
            while (src.length > 1)
            {
                color.h = 360 / (points.length - 1) * (points.length - src.length);
                graphics.lineStyle(3.0, color.value, 0.3);
                graphics.moveTo(src[0].x, src[0].y);
                for (var i:int = 0; i < src.length - 1; i++)
                {
                    var start:Point = src[i];
                    var end:Point = src[i + 1];
                    graphics.lineTo(end.x, end.y);
                    dest.push(Point.interpolate(start, end, 1.0 - t));
                }
                for each (var point:Point in src)
                {
                    graphics.lineStyle(3.0, 0x0);
                    graphics.beginFill(color.value);
                    graphics.drawCircle(point.x, point.y, 4);
                    graphics.endFill();
                }
                src = dest.slice();
                dest = [];
            }
            canvas.graphics.lineTo(src[0].x, src[0].y);
        }
    }
}