Debugging Inspi

I was struck by this Logo procedure in Abelton and diSessa's Turtle Geometry: as the turtle draws a spiral it ends up "unwinding" and retracing its steps. Additionally, feeding the turtle different angles and increments results in wildly different designs. I really liked this five pointed star and thought I would try to port it to the LogoTurtle.

The procedure worked, sort of. The LogoTurtle worked away, but after a while something went awry and, as you can see, the turtle spun and spun. 

I recalled Brian Silverman's idea of not using tail recursion and reached out to him for help changing the Logo procedure. 

to inspi :side :angle :inc repeat 50
 [fd :side
  rt :angle
  make "angle (:angle + :inc)]

Still, this procedure did not produce the expected results.

I programmed the procedure in TurtleArt and realized that the angle quickly grew huge! That explained the eventuality of the LogoTurtle spinning once it got to the third arm of the star.

Checking back in with Brian, he stated that the LogoTurtle code "isn't very smart about angles bigger than 360." Back to the drawing board. 

I changed the LogoTurtle procedure so the largest the angle gets is 362 degrees. Still, the design was not working right.

I realized that the LogoTurtle was not turning far enough from the first spiral unwind to create the next spiral in the right place. Adjusting the increment to 21 did not work (but it did create an interesting new design).

Reflecting on the problem, I edited the procedure to add two degrees after the unwind happens.

Eureka! Success at last! I played around a little with how many degrees the LogoTurtle needed to add to compensate for the mis-calibration, but 2 degrees ended up being enough.

This was a great programming challenge to play with. It required me to really break down the problem and to understand what the turtle was doing at each step. The results were beautiful.