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

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

int main( int argc, char**argv )
{
    float x, y;

    float a = 300;	/* Radius of outer circle */
    float d;
    float e =  5;	/* Points */

    int xc = 500;	/* Screen center X coordinate */
    int yc = 350;	/* Screen center Y coordinate */

    printf( "Usage: star [points]\n" );
    if( argc == 2 ) e = atoi( argv[1] );

    init();
    drawto( a + xc, 0 );
    drawto( a + xc, yc );

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

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

    /* Turn off motor drivers */
    stop();
    return 0;
}
