/* A program to drive a couple of stepper motors */
/* Draw a spiral */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libesketch.h"

int main()
{
    float x, y;

    float a = 300;	/* Outside Radius of spiral */
    float d;		/* Angular position of moving circle */
    float e =  50;	/* Iterations */

    int xm = 1000;	/* Screen X maximum */
    int ym = 660;	/* Screen Y maximum */
    int xc = 500;	/* Screen center X coordinate */
    int yc = 350;	/* Screen center Y coordinate */

    /* Allow hw access */
    init();

    /* Calculate screen center coordinates */
    xc = xm / 2;
    yc = ym / 2;

    /* Reset to center of screen */
    reset( xc, yc );

    /* Calculate outer spiral radius */
    a = yc / ( e * 2 * M_PI );

    /* Draw a spiral */
    for( d = 0; d < e * 2 * M_PI; d += 0.01 )
    {
	/* Calculate x and y */
	x = a * d * cos( d );
	y = a * d * sin( d );

        drawto( x + xc, y + yc );
    }

    /* Turn off motor drivers */
    stop();

    return 0;
}
