[Commit] papers/xr_ols2003/examples splines_tolerance.c,NONE,1.1
Carl Worth
commit@keithp.com
Thu, 15 May 2003 23:47:12 -0700
Committed by: cworth
Update of /local/src/CVS/papers/xr_ols2003/examples
In directory home.keithp.com:/tmp/cvs-serv21300/examples
Added Files:
splines_tolerance.c
Log Message:
Added splines_tolerance.c
--- NEW FILE: splines_tolerance.c ---
#include <Xr.h>
#include "write_png.h"
void
draw_spline (XrState *xrs, double height);
void
draw_splines (XrState *xrs, int width, int height);
#define WIDTH 600
#define HEIGHT 300
#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_splines (xrs, WIDTH, HEIGHT);
write_png_argb32 (image, "splines_tolerance.png", WIDTH, HEIGHT, STRIDE);
XrDestroy (xrs);
return 0;
}
void
draw_spline (XrState *xrs, double height)
{
XrMoveTo (xrs, 0, .1 * height);
height = .8 * height;
XrRelCurveTo (xrs,
-height/2, height/2,
height/2, height/2,
0, height);
XrStroke (xrs);
}
void
draw_splines (XrState *xrs, int width, int height)
{
int i;
double tolerance[5] = {.1, .5, 1, 5, 10};
double line_width = .08 * width;
double gap = width / 6;
XrSetRGBColor (xrs, 0, 0, 0);
XrSetLineWidth (xrs, line_width);
XrTranslate (xrs, gap, 0);
for (i=0; i < 5; i++) {
XrSetTolerance (xrs, tolerance[i]);
draw_spline (xrs, height);
XrTranslate (xrs, gap, 0);
}
}