#!/usr/local/bin/python3

import argparse
from math import *
from dxfwrite import DXFEngine as dxf

parser = argparse.ArgumentParser(description='Generate Vogel Spiral ps file')

parser.add_argument('-p', dest='points', type=int, action='store', help='the number of points to plot', default=100)
parser.add_argument('-s', dest='radius_start', type=int, action='store', help='the radius starting length', default=0)
parser.add_argument('-r', dest='radius_delta', type=float, action='store', help='the radius incr between two adjacent points', default=1)
parser.add_argument('-t', dest='theta_delta', type=float, action='store', help='the theta incr between two adjacent points', default=2*pi/360)
parser.add_argument('-f', dest='file', action='store', help='the ps file to write')
args = parser.parse_args()

print(f"Printing spiral into {args.file} with deltas: r={args.radius_delta}, t={args.theta_delta:06.4f}")

drawing = dxf.drawing(args.file)
# set unit of measurement to mm
drawing.header['$LUNITS'] = 4

vertices = []
r = args.radius_start
theta = 0
for _ in range(args.points):
    r += args.radius_delta
    theta += args.theta_delta

    vertices.append((cos(theta)*r, sin(theta)*r))

polyline= dxf.polyline(linetype='DOT')
polyline.add_vertices(vertices)
drawing.add(polyline)
drawing.save()