
/*
 * Examples of gnuplot_i.c usage
 */

#include <stdio.h>
#include <stdlib.h>

#include <math.h>
#include "gnuplot_i.h"

#define SLEEP_LGTH  2
#define NPOINTS     50

int main(int argc, char *argv[]) 
{
    gnuplot_ctrl    *   h1;
    double              x[NPOINTS] ;
    double              y[NPOINTS] ;
    int                 i ;

    /*
     * Initialize the gnuplot handle
     */
    h1 = gnuplot_init() ;

    double R = 1.0;
    
    double N = 6;

    double da = 2.0* M_PI/N;
    for (i=0; i<=N; i++) {
      x[i] = R*cos(i*da);
      y[i] = R*sin(i*da);
    }

    gnuplot_setstyle(h1, "lines") ;
    gnuplot_cmd(h1, "set size square");
    char cmd[256];
    snprintf(cmd, 255, "set object circle at first %g,%g radius 0.01", x[2],y[2]);
    gnuplot_cmd(h1, cmd); 
    gnuplot_plot_xy(h1, x, y, N+1, "poly") ;
    sleep(SLEEP_LGTH) ;

    printf("*** end of gnuplot example\n") ;
    gnuplot_close(h1) ;
    return 0 ;
}
