Actual source code: ex7.c

petsc-3.9.4 2018-09-11
Report Typos and Errors

  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;

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

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

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

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

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

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

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

109:   PetscDrawDestroy(&draw);
110:   PetscFinalize();
111:   return ierr;
112: }



116: /*TEST

118:    build:
119:      requires: x

121:    test:
122:      output_file: output/ex1_1.out

124: TEST*/