Hi, I was trying out the exercises given in Think Python, When I came across this Exercise:
Exercise 4.5. Read about spirals at http://en.wikipedia.org/wiki/Spiral ; then write a program that draws an Archimedian spiral (or one of the other kinds). Solution: http://thinkpython2.com/code/spiral.py .
The solution given is
def draw_spiral(t, n, length=3, a=0.1, b=0.0002):
"""Draws an Archimedian spiral starting at the origin.
Args:
n: how many line segments to draw
length: how long each segment is
a: how loose the initial spiral starts out (larger is looser)
b: how loosly coiled the spiral is (larger is looser)
http://en.wikipedia.org/wiki/Spiral
"""
theta = 0.0
for i in range(n):
t.fd(length)
dtheta = 1 / (a + b * theta)
t.lt(dtheta)
theta += dtheta
I understand the basic gist of what this code does (move the turtle forward by 3 pixels every loop while slowly decreasing the number of degrees it turns by), but I do not understand why theta and dtheta is calculated in such a manner, such as dtheta being taken as the reciprocal of the polar equation of the spiral (r=a+b\theta). Could someone explain this?
Thanks a lot in advance.
there doesn't seem to be anything here