/* fas.c 1.1 */ /* Copyright 1992, 1993 O'Reilly and Associates, Inc. Permission to use, copy, and modify this program is hereby granted, as long as this copyright notice appears in each copy of the program source code. */ #include "book_utils.h" #define WIN_GEOM "500x500+50+50" /* Structure ID */ static PEXStructure struct_id; #define NUM_CIRCLE_SEGMENTS 40 /* This function builds an array of circle points. */ static void circle( x_center, y_center, radius, num_segments, points ) float x_center; float y_center; float radius; int num_segments; PEXCoord *points; { double delta, angle; int i; angle = 0.0; delta = 2 * M_PI / num_segments; for ( i = 0; i < num_segments; i++, angle += delta ) { points[i].x = x_center + radius * cos( angle ); points[i].y = y_center + radius * sin( angle ); points[i].z = 0.5; } } static void create_structure( dpy ) Display *dpy; { PEXColor color; PEXCoord large[NUM_CIRCLE_SEGMENTS]; PEXCoord small[NUM_CIRCLE_SEGMENTS]; PEXListOfCoord contours[2]; /* Build the contour list -- 2 contours. */ contours[0].count = NUM_CIRCLE_SEGMENTS; contours[0].points = large; contours[1].count = NUM_CIRCLE_SEGMENTS; contours[1].points = small; /* Create the structure. */ struct_id = PEXCreateStructure( dpy ); /* Set the interior style and color. */ PEXSetInteriorStyle( dpy, struct_id, PEXOCStore, PEXInteriorStyleSolid ); SET_COLOR( 1, 1, 1, color ); /* white */ PEXSetSurfaceColor( dpy, struct_id, PEXOCStore, PEXColorTypeRGB, &color ); /* Turn edges on and set their color. */ PEXSetSurfaceEdgeFlag( dpy, struct_id, PEXOCStore, PEXOn ); SET_COLOR( 0, 1, 0, color ); /* green */ PEXSetSurfaceEdgeColor( dpy, struct_id, PEXOCStore, PEXColorTypeRGB, &color ); /* Generate the two circles fully overlapping. */ circle( 0.15, 0.5, 0.1, NUM_CIRCLE_SEGMENTS, large ); circle( 0.15, 0.5, 0.04, NUM_CIRCLE_SEGMENTS, small ); PEXFillAreaSet( dpy, struct_id, PEXOCStore, PEXShapeConvex, False, PEXContourNested, 2, contours ); /* Generate the two circles partially overlapping. */ circle( 0.45, 0.5, 0.1, NUM_CIRCLE_SEGMENTS, large ); circle( 0.55, 0.5, 0.04, NUM_CIRCLE_SEGMENTS, small ); PEXFillAreaSet( dpy, struct_id, PEXOCStore, PEXShapeConvex, False, PEXContourIntersecting, 2, contours ); /* Generate the two circles not overlapping. */ circle( 0.75, 0.5, 0.1, NUM_CIRCLE_SEGMENTS, large ); circle( 0.92, 0.5, 0.04, NUM_CIRCLE_SEGMENTS, small ); PEXFillAreaSet( dpy, struct_id, PEXOCStore, PEXShapeConvex, False, PEXContourDisjoint, 2, contours ); } static void redraw( dpy, window, renderer ) Display *dpy; Window window; PEXRenderer renderer; { XClearWindow( dpy, window ); PEXRenderNetwork( dpy, window, renderer, struct_id ); XFlush( dpy ); } main( argc, argv ) int argc; char *argv[]; { Display *dpy; Window window; XEvent event; XVisualInfo vis_info; XColor bkgd_color; XStandardColormap cmap_info; PEXColorApproxEntry capx_info; PEXRenderer renderer; PEXRendererAttributes rattrs; PEXExtensionInfo *pexinfo; int done = 0; /* Open a display and initialize PEX. */ dpy = ora_init_pex( argv, &pexinfo ); if ( !dpy ) exit(1); /* Determine the best visual to use. */ ora_find_best_visual( dpy, &vis_info ); /* Get a standard colormap for the visual. */ if ( !ora_get_standard_colormap( dpy, &vis_info, &cmap_info ) ) { fprintf ( stderr, "Cannot find a standard colormap\n" ); exit(1); } ora_set_stdcmap_approx( &vis_info, &cmap_info, &capx_info ); /* Create the window, giving it a gray background. */ bkgd_color.red = bkgd_color.green = bkgd_color.blue = 0x5555; bkgd_color.flags = DoRed | DoGreen | DoBlue; window = ora_create_window( dpy, &vis_info, &cmap_info, WIN_GEOM, &bkgd_color ); /* Create the structure and Set up the PEX renderer. */ if ( STRUCTURE_SPT( pexinfo ) ) { create_structure( dpy ); renderer = ora_setup_renderer( dpy, window, &capx_info, &rattrs ); } else { fprintf( stderr, "Structures not supported.\n" ); exit(4); } /* Read and respond to X events. */ XSelectInput( dpy, window, ExposureMask | ButtonPressMask ); while ( !done ) { XNextEvent( dpy, &event ); switch ( event.type ) { case Expose: /* Flush remaining Expose events, then redraw. */ while ( XCheckTypedWindowEvent( dpy, window, Expose, &event ) ) ; /* empty statement */ redraw( dpy, window, renderer ); break; case ButtonPress: done = 1; break; } } XCloseDisplay( dpy ); return 0; }