I'm trying to recreate a function spiral()
using recursion that takes the parameters initLen
(pixel length of first side), N
(angle connecting segments), and mult
(a float amount indicating how much bigger/smaller each segment should be after each turn - ex: mult = 0.5
means each segment would be half the length of the previous). The drawing should stop when the segment length reaches less than 1 or greater than 500.
example of desired output for spiral( 100, 90, 0.9 )
:
I have attempted this:
def spiral( initLen, N, mult ):
if initLen> 500:
return
elif initLen< 1:
return
else:
pendown()
forward(initLen)
left(360.0/N)
spiral((initLen*mult),angle, mult)
Thinking the only thing changing is segment length (by order of the multiplier) each turn.
My program output for spiral( 20, 90, 0.9 )
is....
not quite similar to above...
Any hints?
The example invocation you posted (
spiral( 100, 90, 0.9 )
) seems to treat the second parameter as the degree of each turn whereas you treat it as the number of turns to make a complete 360 degree turn in your code.Either change the call to
spiral(20, 4, 0.9)
or the turn toleft(N)
.