[Commit] papers/xr_ols2003/examples hering.c,NONE,1.1 .cvsignore,1.1,1.2 Makefile,1.1,1.2 outline.c,1.1,1.2 spiral.c,1.1,1.2

Carl Worth commit@keithp.com
Wed, 14 May 2003 19:00:30 -0700


Committed by: cworth

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

Modified Files:
	.cvsignore Makefile outline.c spiral.c 
Added Files:
	hering.c 
Log Message:
Added Hering illusion which has XrSetLineWidth

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

#include "write_png.h"

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

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

char image[STRIDE*HEIGHT];

int
main (void)
{
    XrState *xrs;
    XrSurface *s;

    xrs = XrCreate ();

    s = XrSurfaceCreateForImage (image, XrFormatARGB32,
				 WIDTH, HEIGHT, STRIDE);

    XrSetTargetSurface (xrs, s);

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

    draw_hering (xrs, WIDTH, HEIGHT);

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

    XrSurfaceDestroy (s);
    XrDestroy (xrs);

    return 0;
}

void
draw_hering (XrState *xrs, int width, int height)
{
#define LINES 32
#define MAX_THETA (.80 * M_PI_2)
#define THETA_INC (2 * MAX_THETA / (double) (LINES-1))

    int i;

    XrSetRGBColor (xrs, 0, 0, 0);
    XrSetLineWidth (xrs, 1.0);

    XrSave (xrs);
    {
	XrTranslate (xrs, width / 2, height / 2);
	XrRotate (xrs, MAX_THETA);
	
	for (i=0; i < LINES; i++) {
	    XrMoveTo (xrs, -5 * width, 0);
	    XrLineTo (xrs, 5 * width, 0);
	    XrStroke (xrs);
	    
	    XrRotate (xrs, - THETA_INC);
	}
    }
    XrRestore (xrs);

    XrSetLineWidth (xrs, 4);
    XrSetRGBColor (xrs, 1, 0, 0);

    XrMoveTo (xrs, width / 4, 0);
    XrRelLineTo (xrs, 0, height);
    XrStroke (xrs);

    XrMoveTo (xrs, 3 * width / 4, 0);
    XrRelLineTo (xrs, 0, height);
    XrStroke (xrs);
}

Index: .cvsignore
===================================================================
RCS file: /local/src/CVS/papers/xr_ols2003/examples/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- .cvsignore	14 May 2003 21:04:22 -0000	1.1
+++ .cvsignore	15 May 2003 02:00:28 -0000	1.2
@@ -1,3 +1,4 @@
 outline
 spiral
 *.png
+*.eps

Index: Makefile
===================================================================
RCS file: /local/src/CVS/papers/xr_ols2003/examples/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile	14 May 2003 21:04:22 -0000	1.1
+++ Makefile	15 May 2003 02:00:28 -0000	1.2
@@ -1,9 +1,22 @@
-EXAMPLES=outline spiral
+EXAMPLES=outline.eps spiral.eps hering.eps
 
 CFLAGS=-g -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls `pkg-config --cflags Xr`
-LDFLAGS=write_png.o `pkg-config --libs Xr` -lpng
+LDFLAGS=`pkg-config --libs Xr` -lpng
 
 all: ${EXAMPLES}
 
+.PRECIOUS: outline.png spiral.png hering.png
+
+%.eps: %.png
+	pngtopnm $< | pnmtops -noturn -dpi 300 -equalpixels > $@
+
+%.png: %.bin
+	./$^
+
+%.bin: %.o write_png.o
+	${CC} ${CFLAGS} ${LDFLAGS} $^ -o $@
+
+write_png.o: write_png.c write_png.h
+
 clean:
-	rm -f ${EXAMPLES} *.o
+	rm -f ${EXAMPLES} *.bin *.o

Index: outline.c
===================================================================
RCS file: /local/src/CVS/papers/xr_ols2003/examples/outline.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- outline.c	14 May 2003 21:04:22 -0000	1.1
+++ outline.c	15 May 2003 02:00:28 -0000	1.2
@@ -1,5 +1,3 @@
-#include <string.h> /* for memset */
-
 #include <Xr.h>
 
 #include "write_png.h"
@@ -19,28 +17,32 @@
 XrSurface *
 create_gradient (XrState *xrs, double width, double height);
 
+#define WIDTH 750
+#define HEIGHT 500
+#define STRIDE (WIDTH * 4)
+
+char image[STRIDE*HEIGHT];
+
 int
 main (void)
 {
-    const int width = 600;
-    const int height = 400;
-    const int stride = width * 4;
-    char image[stride*height];
     XrState *xrs;
     XrSurface *s;
 
-    memset (image, 0, stride*height);
-
     xrs = XrCreate ();
 
     s = XrSurfaceCreateForImage (image, XrFormatARGB32,
-				 width, height, stride);
+				 WIDTH, HEIGHT, STRIDE);
 
     XrSetTargetSurface (xrs, s);
 
-    draw_outlines (xrs, width, height);
+    XrRectangle (xrs, 0, 0, WIDTH, HEIGHT);
+    XrSetRGBColor (xrs, 1, 1, 1);
+    XrFill (xrs);
 
-    write_png_argb32 (image, "outline.png", width, height, stride);
+    draw_outlines (xrs, WIDTH, HEIGHT);
+
+    write_png_argb32 (image, "outline.png", WIDTH, HEIGHT, STRIDE);
 
     XrSurfaceDestroy (s);
     XrDestroy (xrs);
@@ -96,10 +98,6 @@
     pad = (surface_width - (3 * width)) / 2.0;
     height = surface_height;
 
-    XrSetRGBColor (xrs, 1, 1, 1);
-    XrRectangle (xrs, 0, 0, surface_width, surface_height);
-    XrFill (xrs);
-
     gradient = create_gradient (xrs, width, height);
 
     XrSetPattern (xrs, gradient);
@@ -121,7 +119,9 @@
 void
 draw_flat (XrState *xrs, double width, double height)
 {
-    XrRectangle (xrs, 0, 0, width, height);
+    double hwidth = width / 2.0;
+
+    XrRectangle (xrs, 0, hwidth, width, height - hwidth);
 
     XrFill (xrs);
 }

Index: spiral.c
===================================================================
RCS file: /local/src/CVS/papers/xr_ols2003/examples/spiral.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- spiral.c	14 May 2003 21:04:22 -0000	1.1
+++ spiral.c	15 May 2003 02:00:28 -0000	1.2
@@ -1,38 +1,36 @@
-#include <string.h> /* for memset */
-
 #include <Xr.h>
 
 #include "write_png.h"
 
 void
-draw_spiral (XrState *xrs, int surface_width, int surface_height);
+draw_spiral (XrState *xrs, int width, int height);
+
+#define WIDTH 600
+#define HEIGHT 600
+#define STRIDE (WIDTH * 4)
+
+char image[STRIDE*HEIGHT];
 
 int
 main (void)
 {
-    const int width = 600;
-    const int height = 600;
-    const int stride = width * 4;
-    char image[stride*height];
     XrState *xrs;
     XrSurface *s;
 
-    memset (image, 0, stride*height);
-
     xrs = XrCreate ();
 
     s = XrSurfaceCreateForImage (image, XrFormatARGB32,
-				 width, height, stride);
+				 WIDTH, HEIGHT, STRIDE);
 
     XrSetTargetSurface (xrs, s);
 
-    XrRectangle (xrs, 0, 0, width, height);
+    XrRectangle (xrs, 0, 0, WIDTH, HEIGHT);
     XrSetRGBColor (xrs, 1, 1, 1);
     XrFill (xrs);
 
-    draw_spiral (xrs, width, height);
+    draw_spiral (xrs, WIDTH, HEIGHT);
 
-    write_png_argb32 (image, "spiral.png", width, height, stride);
+    write_png_argb32 (image, "spiral.png", WIDTH, HEIGHT, STRIDE);
 
     XrSurfaceDestroy (s);
     XrDestroy (xrs);
@@ -43,23 +41,20 @@
 void
 draw_spiral (XrState *xrs, int width, int height)
 {
-#define BOXES (9)
-#define DECAY (1.0 / (6.0 * (BOXES - 1)))
-
-    int wdelta = DECAY * width;
-    int hdelta = DECAY * height;
+    int wd = .02 * width;
+    int hd = .02 * height;
     int i;
 
     XrTranslate (xrs, 1, 1);
     width -= 2;
     height -= 2;
 
-    XrMoveTo (xrs, width, -hdelta);
-    for (i=0; i < BOXES; i++) {
-	XrRelLineTo (xrs, 0, height - hdelta * (2 * i - 1));
-	XrRelLineTo (xrs, - (width - wdelta * (2 *i)), 0);
-	XrRelLineTo (xrs, 0, - (height - hdelta * (2*i)));
-	XrRelLineTo (xrs, width - wdelta * (2 * i + 1), 0);
+    XrMoveTo (xrs, width, -hd);
+    for (i=0; i < 9; i++) {
+	XrRelLineTo (xrs, 0, height - hd * (2 * i - 1));
+	XrRelLineTo (xrs, - (width - wd * (2 *i)), 0);
+	XrRelLineTo (xrs, 0, - (height - hd * (2*i)));
+	XrRelLineTo (xrs, width - wd * (2 * i + 1), 0);
     }
 
     XrSetRGBColor (xrs, 0, 0, 1);