Actual source code: ex7.c


  2: static char help[] = "Demonstrates drawing primitives in a window\n";

  4: #include <petscdraw.h>

  6: int main(int argc,char **argv)
  7: {
  8:   PetscDraw draw;

 10:   int i,j,w,h;
 11:   int k  = PETSC_DRAW_BLACK;
 12:   int r  = PETSC_DRAW_RED;
 13:   int g  = PETSC_DRAW_GREEN;
 14:   int b  = PETSC_DRAW_BLUE;
 15:   int y  = PETSC_DRAW_YELLOW;
 16:   int c0 = PETSC_DRAW_BASIC_COLORS;
 17:   int c2 = 255;
 18:   int c1 = (c0+c2)/2;

 20:   PetscInitialize(&argc,&argv,NULL,help);

 22:   PetscDrawCreate(PETSC_COMM_WORLD,0,"Draw Example",PETSC_DECIDE,PETSC_DECIDE,101,101,&draw);
 23:   /*PetscDrawSetPause(draw,2.0);*/
 24:   PetscDrawSetFromOptions(draw);

 26:   PetscDrawCheckResizedWindow(draw);
 27:   PetscDrawGetWindowSize(draw,&w,&h);
 28:   PetscDrawSetCoordinates(draw,0,0,--w,--h);
 29:   PetscDrawClear(draw);
 30:   /* one-pixel lines in the window corners */
 31:   PetscDrawLine(draw,0,0,0,0,r);
 32:   PetscDrawLine(draw,w,0,w,0,r);
 33:   PetscDrawLine(draw,0,h,0,h,r);
 34:   PetscDrawLine(draw,w,h,w,h,r);
 35:   /* border lines with two pixels from  borders */
 36:   PetscDrawLine(draw,0+2,0,w-2,0,k);
 37:   PetscDrawLine(draw,0+2,h,w-2,h,k);
 38:   PetscDrawLine(draw,0,0+2,0,h-2,k);
 39:   PetscDrawLine(draw,w,0+2,w,h-2,k);
 40:   /* oblique lines */
 41:   PetscDrawLine(draw,0+2,h/2,w-2,h-2,b);
 42:   PetscDrawLine(draw,0+1,h-1,w-1,0+1,b);
 43:   /* vertical up and down arrow, two pixels from borders  */
 44:   PetscDrawArrow(draw,1*w/4,0+2,1*w/4,h-2,g);
 45:   PetscDrawArrow(draw,3*w/4,h-2,3*w/4,0+2,g);
 46:   /* horizontal right and left arrow, two pixels from borders  */
 47:   PetscDrawArrow(draw,0+2,3*h/4,w-2,3*h/4,g);
 48:   PetscDrawArrow(draw,w-2,1*h/4,0+2,1*h/4,g);
 49:   /* flush, save, and pause */
 50:   PetscDrawFlush(draw);
 51:   PetscDrawSave(draw);
 52:   PetscDrawPause(draw);

 54:   PetscDrawCheckResizedWindow(draw);
 55:   PetscDrawGetWindowSize(draw,&w,&h);
 56:   PetscDrawSetCoordinates(draw,0,0,--w,--h);
 57:   PetscDrawClear(draw);
 58:   /* one-pixel rectangles in the window corners */
 59:   PetscDrawRectangle(draw,0,0,0,0,k,k,k,k);
 60:   PetscDrawRectangle(draw,w,0,w,0,k,k,k,k);
 61:   PetscDrawRectangle(draw,0,h,0,h,k,k,k,k);
 62:   PetscDrawRectangle(draw,w,h,w,h,k,k,k,k);
 63:   /* border rectangles with two pixels from  borders */
 64:   PetscDrawRectangle(draw,0+2,0,w-2,0,k,k,k,k);
 65:   PetscDrawRectangle(draw,0+2,h,w-2,h,k,k,k,k);
 66:   PetscDrawRectangle(draw,0,0+2,0,h-2,k,k,k,k);
 67:   PetscDrawRectangle(draw,w,0+2,w,h-2,k,k,k,k);
 68:   /* more rectangles */
 69:   PetscDrawRectangle(draw,0+2,0+2,w/2-1,h/2-1,b,b,b,b);
 70:   PetscDrawRectangle(draw,0+2,h/2+1,w/2-1,h-2,r,r,r,r);
 71:   PetscDrawRectangle(draw,w/2+1,h/2+1,w-2,h-2,g,g,g,g);
 72:   PetscDrawRectangle(draw,w/2+1,0+2,w-2,h/2-1,y,y,y,y);
 73:   /* flush, save, and pause */
 74:   PetscDrawFlush(draw);
 75:   PetscDrawSave(draw);
 76:   PetscDrawPause(draw);

 78:   PetscDrawCheckResizedWindow(draw);
 79:   PetscDrawGetWindowSize(draw,&w,&h);
 80:   PetscDrawSetCoordinates(draw,0,0,--w,--h);
 81:   PetscDrawClear(draw);
 82:   /* interpolated triangles, one pixel from borders */
 83:   PetscDrawTriangle(draw,0+1,0+1,w-1,0+1,w-1,h-1,c0,c1,c2);
 84:   PetscDrawTriangle(draw,0+1,0+1,0+1,h-1,w-1,h-1,c0,c1,c2);
 85:   /* interpolated triangle, oblique, inside canvas */
 86:   PetscDrawTriangle(draw,w/4,h/4,w/2,3*h/4,3*w/4,h/2,c2,c1,c0);
 87:   /* flush, save, and pause */
 88:   PetscDrawFlush(draw);
 89:   PetscDrawSave(draw);
 90:   PetscDrawPause(draw);

 92:   PetscDrawCheckResizedWindow(draw);
 93:   PetscDrawGetWindowSize(draw,&w,&h);
 94:   PetscDrawSetCoordinates(draw,0,0,--w,--h);
 95:   PetscDrawClear(draw);
 96:   /* circles and ellipses */
 97:   PetscDrawEllipse(draw,w/2,h/2,w-1,h-1,r);
 98:   PetscDrawEllipse(draw,w,h/2,w/2,h,g);
 99:   PetscDrawEllipse(draw,0,0,w,h/2,b);
100:   PetscDrawEllipse(draw,w/4,3*h/4,w/2,h/4,y);
101:   PetscDrawCoordinateToPixel(draw,w/2,h/2,&i,&j);
102:   PetscDrawPointPixel(draw,i,j,k);
103:   /* flush, save, and pause */
104:   PetscDrawFlush(draw);
105:   PetscDrawSave(draw);
106:   PetscDrawPause(draw);

108:   PetscDrawDestroy(&draw);
109:   PetscFinalize();
110:   return 0;
111: }

113: /*TEST

115:    build:
116:      requires: x

118:    test:
119:      output_file: output/ex1_1.out

121: TEST*/