Actual source code: ex7.c
petsc-3.7.3 2016-08-01
2: static char help[] = "Demonstrates drawing primitives in a window\n";
4: #include <petscdraw.h>
8: int main(int argc,char **argv)
9: {
10: PetscDraw draw;
13: int i,j,w,h;
14: int k = PETSC_DRAW_BLACK;
15: int r = PETSC_DRAW_RED;
16: int g = PETSC_DRAW_GREEN;
17: int b = PETSC_DRAW_BLUE;
18: int y = PETSC_DRAW_YELLOW;
19: int c0 = PETSC_DRAW_BASIC_COLORS;
20: int c2 = 255;
21: int c1 = (c0+c2)/2;
23: PetscInitialize(&argc,&argv,NULL,help);
25: PetscDrawCreate(PETSC_COMM_WORLD,0,"Draw Example",PETSC_DECIDE,PETSC_DECIDE,101,101,&draw);
26: /*PetscDrawSetPause(draw,2.0);*/
27: PetscDrawSetFromOptions(draw);
29: PetscDrawCheckResizedWindow(draw);
30: PetscDrawGetWindowSize(draw,&w,&h);
31: PetscDrawSetCoordinates(draw,0,0,--w,--h);
32: PetscDrawClear(draw);
33: /* one-pixel lines in the window corners */
34: PetscDrawLine(draw,0,0,0,0,r);
35: PetscDrawLine(draw,w,0,w,0,r);
36: PetscDrawLine(draw,0,h,0,h,r);
37: PetscDrawLine(draw,w,h,w,h,r);
38: /* border lines with two pixels from borders */
39: PetscDrawLine(draw,0+2,0,w-2,0,k);
40: PetscDrawLine(draw,0+2,h,w-2,h,k);
41: PetscDrawLine(draw,0,0+2,0,h-2,k);
42: PetscDrawLine(draw,w,0+2,w,h-2,k);
43: /* oblique lines */
44: PetscDrawLine(draw,0+2,h/2,w-2,h-2,b);
45: PetscDrawLine(draw,0+1,h-1,w-1,0+1,b);
46: /* vertical up and down arrow, two pixels from borders */
47: PetscDrawArrow(draw,1*w/4,0+2,1*w/4,h-2,g);
48: PetscDrawArrow(draw,3*w/4,h-2,3*w/4,0+2,g);
49: /* horizontal right and left arrow, two pixels from borders */
50: PetscDrawArrow(draw,0+2,3*h/4,w-2,3*h/4,g);
51: PetscDrawArrow(draw,w-2,1*h/4,0+2,1*h/4,g);
52: /* flush, save, and pause */
53: PetscDrawFlush(draw);
54: PetscDrawSave(draw);
55: PetscDrawPause(draw);
57: PetscDrawCheckResizedWindow(draw);
58: PetscDrawGetWindowSize(draw,&w,&h);
59: PetscDrawSetCoordinates(draw,0,0,--w,--h);
60: PetscDrawClear(draw);
61: /* one-pixel rectangles in the window corners */
62: PetscDrawRectangle(draw,0,0,0,0,k,k,k,k);
63: PetscDrawRectangle(draw,w,0,w,0,k,k,k,k);
64: PetscDrawRectangle(draw,0,h,0,h,k,k,k,k);
65: PetscDrawRectangle(draw,w,h,w,h,k,k,k,k);
66: /* border rectangles with two pixels from borders */
67: PetscDrawRectangle(draw,0+2,0,w-2,0,k,k,k,k);
68: PetscDrawRectangle(draw,0+2,h,w-2,h,k,k,k,k);
69: PetscDrawRectangle(draw,0,0+2,0,h-2,k,k,k,k);
70: PetscDrawRectangle(draw,w,0+2,w,h-2,k,k,k,k);
71: /* more rectangles */
72: PetscDrawRectangle(draw,0+2,0+2,w/2-1,h/2-1,b,b,b,b);
73: PetscDrawRectangle(draw,0+2,h/2+1,w/2-1,h-2,r,r,r,r);
74: PetscDrawRectangle(draw,w/2+1,h/2+1,w-2,h-2,g,g,g,g);
75: PetscDrawRectangle(draw,w/2+1,0+2,w-2,h/2-1,y,y,y,y);
76: /* flush, save, and pause */
77: PetscDrawFlush(draw);
78: PetscDrawSave(draw);
79: PetscDrawPause(draw);
81: PetscDrawCheckResizedWindow(draw);
82: PetscDrawGetWindowSize(draw,&w,&h);
83: PetscDrawSetCoordinates(draw,0,0,--w,--h);
84: PetscDrawClear(draw);
85: /* interpolated triangles, one pixel from borders */
86: PetscDrawTriangle(draw,0+1,0+1,w-1,0+1,w-1,h-1,c0,c1,c2);
87: PetscDrawTriangle(draw,0+1,0+1,0+1,h-1,w-1,h-1,c0,c1,c2);
88: /* interpolated triangle, oblique, inside canvas */
89: PetscDrawTriangle(draw,w/4,h/4,w/2,3*h/4,3*w/4,h/2,c2,c1,c0);
90: /* flush, save, and pause */
91: PetscDrawFlush(draw);
92: PetscDrawSave(draw);
93: PetscDrawPause(draw);
95: PetscDrawCheckResizedWindow(draw);
96: PetscDrawGetWindowSize(draw,&w,&h);
97: PetscDrawSetCoordinates(draw,0,0,--w,--h);
98: PetscDrawClear(draw);
99: /* circles and ellipses */
100: PetscDrawEllipse(draw,w/2,h/2,w-1,h-1,r);
101: PetscDrawEllipse(draw,w,h/2,w/2,h,g);
102: PetscDrawEllipse(draw,0,0,w,h/2,b);
103: PetscDrawEllipse(draw,w/4,3*h/4,w/2,h/4,y);
104: PetscDrawCoordinateToPixel(draw,w/2,h/2,&i,&j);
105: PetscDrawPointPixel(draw,i,j,k);
106: /* flush, save, and pause */
107: PetscDrawFlush(draw);
108: PetscDrawSave(draw);
109: PetscDrawPause(draw);
111: PetscDrawDestroy(&draw);
112: PetscFinalize();
113: return 0;
114: }