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

forked from: RecursiveSpiral

Get Adobe Flash player
by Junka 13 Sep 2012
/**
 * Copyright Junka ( http://wonderfl.net/user/Junka )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mmIq
 */

// forked from natehorstmann's RecursiveSpiral
package 
{
    import flash.text.TextField;
    import flash.display.Shape;    
    import flash.display.Graphics;
    import flash.display.Sprite;
    public class RecursiveSpiral extends Sprite {
        
        // getting stack overflow if this is too high
        private const MAX_RECURSIONS :int = 1000;
        private var tf:TextField;
        
        public function RecursiveSpiral() {
            this.tf = new TextField();
            this.tf.width = this.stage.stageWidth;
            this.tf.height = this.stage.stageHeight;
            this.tf.multiline = true;
            this.tf.wordWrap = true;
            this.addChild(this.tf);
            
            _trace('==========');
            
            var spiral : Shape = new Shape();
            spiral.x = stage.stageWidth * 0.5;
            spiral.y = stage.stageHeight * 0.5;
            spiral.graphics.lineStyle(1);
            addChild(spiral);
            
            var numRevolutions : Number = 3;
            var radius : Number = 200;
               
            drawSpiral(spiral.graphics, int(360 * numRevolutions), radius);
            
        }
        
        private function drawSpiral(g:Graphics, degrees : int, radius : Number, rate :Number = 0, resolution : int = 0) : void
        {
            if (degrees > 0) 
            {
                var rad : Number = degrees * Math.PI/180;
                radius -= resolution*rate;
                
                if (rate == 0 )
                {     
                    rate = radius/degrees;
                    resolution = int(degrees/MAX_RECURSIONS);
                    g.moveTo(radius*Math.cos(rad), radius*Math.sin(rad));
                    //_trace(radius*Math.cos(rad), radius*Math.sin(rad));
                }
                
                g.lineTo(radius*Math.cos(rad), radius*Math.sin(rad));
                //_trace(radius*Math.cos(rad), radius*Math.sin(rad));
                
                degrees -= resolution;
                drawSpiral(g, degrees, radius, rate, resolution);
            }
        }
        
        private function _trace(...arg):void {
           this.tf.appendText(arg.join(' ') + '\n');
        }
    }
}