/* fasd.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_SEGMENTS 40 #define RADIUS 0.10 #define SPACING 0.20 /* This function builds an array of circle points. */ static void circle( center, points ) PEXCoord2D *center; PEXCoord *points; { double delta, angle; int i; delta = 2 * M_PI / NUM_SEGMENTS; for ( i = 0, angle = 0; i < NUM_SEGMENTS; i++, angle += delta ) { points[i].x = center->x + RADIUS * cos( angle ); points[i].y = center->y + RADIUS * sin( angle ); points[i].z = 0.0; } } #define SET_RGB( r, g, b, c ) \ {(c).red = (r); (c).green = (g); (c).blue = (b);} static void create_structure( dpy ) Display *dpy; { PEXCoord verts[8][NUM_SEGMENTS]; PEXListOfVertex areas[8]; PEXFacetData facet_colors[8]; PEXCoord2D location; float angle; unsigned int facet_data_flag, vertex_data_flag, i; /* Build the background fill area. */ verts[0][0].x = 0; verts[0][0].y = 0; verts[0][0].z = 0; verts[0][1].x = 1; verts[0][1].y = 0; verts[0][1].z = 0; verts[0][2].x = 1; verts[0][2].y = 1; verts[0][2].z = 0; verts[0][3].x = 0; verts[0][3].y = 1; verts[0][3].z = 0; areas[0].count = 4; areas[0].vertices.no_data = verts[0]; /* Build the outer vertices. */ for ( i = 1, angle = M_PI/2; i < 7; i++, angle += M_PI/3 ) { location.x = 0.5 + (SPACING + RADIUS) * cos( angle ); location.y = 0.5 + (SPACING + RADIUS) * sin( angle ); circle( &location, verts[i] ); areas[i].count = NUM_SEGMENTS; areas[i].vertices.no_data = verts[i]; } /* Build the circle in the center. */ location.x = 0.5; location.y = 0.5; circle( &location, verts[7] ); areas[7].count = NUM_SEGMENTS; areas[7].vertices.no_data = verts[7]; /* Set the facet colors. */ SET_RGB(0, 0, 0, facet_colors[0].rgb); /* black */ SET_RGB(1, 0, 0, facet_colors[1].rgb); /* red */ SET_RGB(1, 1, 0, facet_colors[2].rgb); /* yellow */ SET_RGB(0, 1, 0, facet_colors[3].rgb); /* green */ SET_RGB(0, 1, 1, facet_colors[4].rgb); /* cyan */ SET_RGB(0, 0, 1, facet_colors[5].rgb); /* blue */ SET_RGB(1, 0, 1, facet_colors[6].rgb); /* magenta */ SET_RGB(1, 1, 1, facet_colors[7].rgb); /* white */ /* Create the structure. */ struct_id = PEXCreateStructure( dpy ); /* Set the interior style. */ PEXSetInteriorStyle( dpy, struct_id, PEXOCStore, PEXInteriorStyleSolid ); /* Create the fill area set with data primitives. */ facet_data_flag = PEXGAColor; vertex_data_flag = PEXGANone; for ( i = 0; i < 8; i++ ) PEXFillAreaSetWithData( dpy, struct_id, PEXOCStore, PEXShapeConvex, False, PEXContourDisjoint, facet_data_flag, vertex_data_flag, PEXColorTypeRGB, 1, &facet_colors[i], &areas[i] ); } 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(1); } /* 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; }