# AS Quiz #13

Today’s quiz is not multiple choice. Instead, your task is to draw a spiral using a recursive function.

Optionally you can alter your function to draw other types of spiral forms:

(You can view various solutions in the comments - as well as my solution at wonderfl)

1. Nate
Posted January 28, 2010 at 1:19 pm | Permalink

Here’s my attempt: http://wonderfl.net/code/37cf80197e3650470ed5771e1b9bd7e30552fd63

I may be cheating because I had to add in a const to keep from getting too many recursions if the number of degrees is large, and am passing some initializing variables into the function…

2. Posted January 28, 2010 at 1:23 pm | Permalink

nicely done… you could replace the const by adding a default var at the end of your arguments … max:int = 1000):void {…

3. altschuler
Posted January 28, 2010 at 3:16 pm | Permalink

This is recursive or anything, it’s just fun to watch :-]

http://wonderfl.net/code/bd7d28b1eed18c0f74eeea47e076efb91efa6e8b

4. altschuler
Posted January 28, 2010 at 5:27 pm | Permalink

was supposed to say “isn’t recursive”

5. DieTapete
Posted January 28, 2010 at 5:53 pm | Permalink

This is my approach:

var g:Graphics = graphics;
g.lineStyle(1, 0×000000);
g.moveTo(stage.stageWidth/2, stage.stageHeight/2);
drawSpiral(0, 0);
function drawSpiral(r, alpha){
g.lineTo(stage.stageWidth/2+r*Math.cos(alpha), stage.stageHeight/2+r*Math.sin(alpha));
if (r>100)
return;

drawSpiral(r+1,alpha+0.2);
}

6. Posted January 29, 2010 at 8:43 am | Permalink

@altschuler - it’s nice to have a non-recursive version since I wasn’t planning on posting one.

@DieTapete - Nicely done