/* CGminimal.c
    To get the output to stdout, invoke the program with an argument '-', i.e.,
    CGminimal -  > CGminimal.eps
*/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <cgraph.h>
#define PI	3.141592654

void plot_something(char *progname, int use_stdout)
{
int 	rot= 1;			/* Portrait=1, Landscape=0 */
int 	expand= 1;		/* left over from PC version, not used in NeXT Cgraph */
float	scale= 1.0;		/* scaling factor */
float   radius1= 0.8, radius2= 1.2;	/* analysis or plot parameters */
int i;
float x, y, angle;

	if(use_stdout)
	   cg_use_stdout(use_stdout);	/* decide where to send output */
	cg_useflexcolor(2);		/* let the device capability dictate color/monochrome */
	cg_setboundingbox("0 0 216 216");
	cg_init(rot, expand, scale);	/* expand is not used in cg_init() but for compatibility */
	cg_aorigin(1.5, 1.5);		/* move origin to center of BoundingBox */

	for(i=0; i<=200; i++) {
	    angle = PI*(float)i/100.0;
	    x = radius2 * cos(3.0*angle);
	    y = radius2 * sin(5.0*angle);
	    if(i) cg_line(x, y);
	    else  cg_move(x, y);		/* first point */
	}
	cg_closepath();

	cg_gsave();
	cg_grayrgbcolor(0.6, 1.0, 0.6, 0.6);
	cg_eofill();
	cg_grestore();

/* void cg_grayrgbcolor(float gray, float r, float g, float b); */
	cg_grayrgbcolor(0.0,  0.0, 0.0, 1.0);	/* black for gray, and blue for color */
	cg_stroke();	/* strokes the two circles */


	cg_showpage();
}


void main(int argc, char **argv)
{
int use_stdout=0;
    if(argc >= 2  && strncmp(argv[1], "-", 1) == 0)	/* if arg is "-", output to stdout */
	use_stdout = 1;

    plot_something(argv[0], use_stdout);
}

