/* pseudo.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" #define NUM_REDS 6 #define NUM_GREENS 6 #define NUM_BLUES 6 static Display *dpy; static Window window; static PEXStructure struct_id; static PEXRenderer renderer; static void redraw() { XClearWindow( dpy, window ); PEXRenderNetwork( dpy, window, renderer, struct_id ); XFlush( dpy ); } #define X0 0.3 #define XN 0.7 #define Y0 0.1 #define YN 0.9 static void create_structure( nr, ng, nb ) int nr, ng, nb; { int i, j, k, num_colors; double y, dy; PEXColor color; PEXCoord2D pts[4]; num_colors = nr * ng * nb; dy = (YN - Y0) / num_colors; /* Create the structure. */ struct_id = PEXCreateStructure( dpy ); /* Set the interior style to solid. */ PEXSetInteriorStyle( dpy, struct_id, PEXOCStore, PEXInteriorStyleSolid ); /* Create the fill areas, one for each color. */ y = YN; for ( i = 0; i < nr; i++ ) { for ( j = 0; j < ng; j++ ) { for ( k = 0; k < nb; k++ ) { color.rgb.red = i * 1.0 / (nr - 1); color.rgb.green = j * 1.0 / (ng - 1); color.rgb.blue = k * 1.0 / (nb - 1); PEXSetSurfaceColor( dpy, struct_id, PEXOCStore, PEXColorTypeRGB, &color ); pts[0].x = pts[1].x = X0; pts[2].x = pts[3].x = XN; pts[0].y = pts[3].y = y; pts[1].y = pts[2].y = y - dy; PEXFillArea2D( dpy, struct_id, PEXOCStore, PEXShapeConvex, False, 4, pts ); y -= dy; } } } } main( argc, argv ) int argc; char *argv[]; { XEvent event; XVisualInfo *vis_info, vis_templ; XColor bkgd_color; XStandardColormap cmap_info; PEXColorApproxEntry capx_info; PEXExtensionInfo *pexinfo; PEXRendererAttributes rattrs; int done = 0, num_vis; /* Open a display and initialize PEX. */ dpy = ora_init_pex( argv, &pexinfo ); if ( !dpy ) exit(1); /* Get an 8-bit PseudoColor visual. */ vis_templ.screen = DefaultScreen( dpy ); vis_templ.depth = 8; vis_templ.class = PseudoColor; vis_info = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask | VisualClassMask , &vis_templ, &num_vis ); if ( num_vis == 0 ) { fprintf ( stderr, "No 8-bit PseudoColor visual.\n" ); exit(1); } /* Create a colormap for the visual. */ if ( !ora_create_pseudo_map( dpy, vis_info, NUM_REDS, NUM_GREENS, NUM_BLUES, &cmap_info, &capx_info ) ) { fprintf ( stderr, "Cannot create a colormap\n" ); exit(1); } capx_info.dither = PEXOff; /* 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 renderer and the structure. */ if ( STRUCTURE_SPT( pexinfo ) ) { renderer = ora_setup_renderer( dpy, window, &capx_info, &rattrs ); create_structure( NUM_REDS, NUM_GREENS, NUM_BLUES ); } 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(); break; case ButtonPress: done = 1; break; } } XCloseDisplay( dpy ); return 0; }