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)
6 Comments
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…
nicely done… you could replace the const by adding a default var at the end of your arguments … max:int = 1000):void {…
This is recursive or anything, it’s just fun to watch :-]
http://wonderfl.net/code/bd7d28b1eed18c0f74eeea47e076efb91efa6e8b
was supposed to say “isn’t recursive”
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);
}
@altschuler - it’s nice to have a non-recursive version since I wasn’t planning on posting one.
@DieTapete - Nicely done