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-9-30

Get Adobe Flash player
by kihon 30 Sep 2011
    Embed
package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.geom.Point;
    import flash.utils.Timer;
    import frocessing.color.ColorHSV;
    
    public class Main extends Sprite
    {
        private const WIDTH:Number = 465;
        private const HEIGHT:Number = 465;
        private var h:Number;
        private var color:ColorHSV = new ColorHSV();
        private var timer:Timer;
        
        public function Main()
        {
            timer = new Timer(10, 100);
            timer.addEventListener(TimerEvent.TIMER, onTimer);
            
            onMouseClick();
            stage.addEventListener(MouseEvent.CLICK, onMouseClick);
        }
        
        private function onMouseClick(event:MouseEvent = null):void
        {
            if (timer.running) return;
            timer.reset();
            graphics.clear();
            color.value = 0x0;
            h = 40;
            timer.start();
        }
        
        private function onTimer(event:TimerEvent):void 
        {
            h += 5;
            
            graphics.beginFill(color.value);
            color.v += 0.01;

            graphics.moveTo(0, h);
            divide(new Point(0, h), new Point(WIDTH, h), 200);
            graphics.lineTo(WIDTH, h);
            graphics.lineTo(WIDTH, HEIGHT);
            graphics.lineTo(0, HEIGHT);
            graphics.lineTo(0, h);
            graphics.endFill();
        }
        
        
        private function divide(a:Point, b:Point, height:Number):void
        {
            if (Math.abs(a.x - b.x) < 1)
            {
                graphics.lineTo(a.x, a.y);
                return;
            }
            
            var middle:Point = Point.interpolate(a, b, 0.5);
            middle.y += Math.random() * height - height / 2;
            divide(a, middle, height / 2);
            divide(middle, b, height / 2);
        }
    }
}