print "%"

from math import *
#this is really begging for a gui with sliders that move automatically

#constraint determines where the spiral begins and ends
#constraint="angle"
constraint="radius"
#constraint="length"

start_a=.3*(2*pi)
end_a  =8*(2*pi)

start_r=1.5
end_r  =5

slope = (end_r-start_r)/(end_a-start_a)
print "(slope: %f)" % slope

#see below for how these formulas were derived
if constraint=="angle":
  start_l=slope*start_a**2
  end_l  =slope*end_a**2
if constraint=="radius":
  start_l=start_r**2/slope
  end_l  =end_r**2/slope
if constraint=="length":
  start_l=12.345
  end_l  =67.890

a=start_a
r=start_r
l=start_l

dl=2

scale=1
print "g0 x0 y0" #need this for arcs for some reason


#l is the parameter, corresponding to length traveled along the spiral
while l<end_l:
    #dl=dr*da approximating a circle
    #slope=dr/da  more or less
    #da=slope*da^2  by substitution
    #da=sqrt(dl/slope) solve for dt
    #therefore, by the power of greyskull:
    a=sqrt(l/slope)

    r=slope*a
    x=cos(a)*(r)*scale
    y=sin(a)*(r)*scale
    print "(l:%f a:%f  r:%f)" % (l, a, r)
    #print "G1 F500 X%f Y%f" % (x, y)
    print "G3 F500 X%f Y%f R%f" % (x, y, r)
    
    l+=dl

    
print "%"

