solution_017c.py

#!/usr/bin/python3
# ==================================================================
# Draw an logarithmic spiral
# I am not sure I have the right formula for a logarithmic spiral.
# I put this formula together from information I found on the web.
# I think it is close to a correct formula.
# ==================================================================

from math import pi, radians, cos, sin, exp
import graphics as gr
import user_interface as ui
import coordinate_conversion as cc
import draw_axes as ax

window_width  = 801
window_height = 801

# -------------------------------------------------------------------
# ---- draw a circle
# -------------------------------------------------------------------

def draw_circle(win,x,y,color):

    wx,wy = cc.center_to_win_coords(x,y,window_width,window_height)
    c = gr.Circle(gr.Point(wx,wy),2)
    c.setWidth(1)
    c.setFill(color)
    c.draw(win)


# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------

win = gr.GraphWin("Archimedes Spiral",window_width,window_height)
win.setBackground("white")

ax.draw_xy_axes(win,True)

a = 2
b = 0.5 

for deg in range(0,811,10):

    rad = radians(deg)

    r = a * exp(b*rad) 

    x = r * sin(rad)
    y = r * cos(rad)

    draw_circle(win,x,y,'red')

ui.pause()

win.close()