[Commit] papers/xr_ols2003/examples stars.c,NONE,1.1 Makefile,1.3,1.4

Carl Worth commit@keithp.com
Thu, 15 May 2003 13:04:51 -0700


Committed by: cworth

Update of /local/src/CVS/papers/xr_ols2003/examples
In directory home.keithp.com:/tmp/cvs-serv16992/examples

Modified Files:
	Makefile 
Added Files:
	stars.c 
Log Message:
Added some figure references. Added stars example

--- NEW FILE: stars.c ---
#include <Xr.h>
#include <math.h>

#include "write_png.h"

void
draw_stars (XrState *xrs, int width, int height);

void
star_path (XrState *xrs);

#define WIDTH 600
#define HEIGHT 275
#define STRIDE (WIDTH * 4)

char image[STRIDE*HEIGHT];

int
main (void)
{
    XrState *xrs;

    xrs = XrCreate ();

    XrSetTargetImage (xrs, image, XrFormatARGB32,
		      WIDTH, HEIGHT, STRIDE);

    XrRectangle (xrs, 0, 0, WIDTH, HEIGHT);
    XrSetRGBColor (xrs, 1, 1, 1);
    XrFill (xrs);

    draw_stars (xrs, WIDTH, HEIGHT);

    write_png_argb32 (image, "stars.png", WIDTH, HEIGHT, STRIDE);

    XrDestroy (xrs);

    return 0;
}

void
star_path (XrState *xrs)
{
    int i;
    double theta = 4 * M_PI / 5.0;

    XrMoveTo (xrs, 0, 0);
    for (i=0; i < 4; i++) {
	XrRelLineTo (xrs, 1.0, 0);
	XrRotate (xrs, theta);
    }
    XrRotate (xrs, theta);
    XrRotate (xrs, theta);
    XrRotate (xrs, theta);
    XrClosePath (xrs);
}

void
draw_stars (XrState *xrs, int width, int height)
{
    XrSetRGBColor (xrs, 0, 0, 0);

    XrSave (xrs);
    {
	XrTranslate (xrs, 5, height / 2.6);
	XrScale (xrs, height, height);
	star_path (xrs);
	XrSetFillRule (xrs, XrFillRuleWinding);
	XrFill (xrs);
    }
    XrRestore (xrs);

    XrSave (xrs);
    {
	XrTranslate (xrs, width - height - 5, height / 2.6);
	XrScale (xrs, height, height);
	star_path (xrs);
	XrSetFillRule (xrs, XrFillRuleEvenOdd);
	XrFill (xrs);
    }
    XrRestore (xrs);
}

Index: Makefile
===================================================================
RCS file: /local/src/CVS/papers/xr_ols2003/examples/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile	15 May 2003 17:34:17 -0000	1.3
+++ Makefile	15 May 2003 20:04:48 -0000	1.4
@@ -1,5 +1,5 @@
-EXAMPLES = outline.eps spiral.eps hering.eps caps_joins.eps
-.PRECIOUS: outline.png spiral.png hering.png caps_joins.png
+EXAMPLES = outline.eps spiral.eps hering.eps caps_joins.eps stars.eps
+.PRECIOUS: outline.png spiral.png hering.png caps_joins.png stars.png
 
 CFLAGS=-g -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls `pkg-config --cflags Xr`
 LDFLAGS=`pkg-config --libs Xr` -lpng