I'm learning Python (for fun) through the book ThinkPython. So far I'm really enjoying this new hobby. One of the recent exercise was crafting a Archimedes spiral.In order to test my skills I've been working on making a hyperbolic spiral but have been stumped!
according to the equation r=a+b*theta^(1/c)
I'm using the following code and would appreciate any help towards the right direction.
import turtle
import math
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.1
for i in range(n):
t.fd(length)
dtheta = 1/((a + b * (theta**(1/-1))))
t.lt(dtheta)
theta += dtheta
# create the world and bob
bob = turtle.Turtle()
draw_spiral(bob, n=1000)
turtle.mainloop()
"""Source code from ThinkPython @ http://greenteapress.com/thinkpython2/code/spiral.py
edited to attempt a hyperbolic spiral"""
many thanks!
Simply adjusting the constants passed to draw_spiral()
as arguments:
def draw_spiral(t, n, length=1, a=0.01, b=60):
I was able to generate a spiral along the lines you describe:
However, it draws from the outside in, not the inside out. So, may not be what you're looking for.