This example shows how to create simple plot using circle and line primitives.
The program produces the following picture:

1 #pragma _fpath "../lib" 2 #pragma _lpath "../dl" 3 #pragma _ipath "../include" 4 5 #include "chlibplot.h" 6 #include <stdlib.h> 7 #include <math.h> 8 9 void make_plot(void); 10 11 int main() 12 { 13 int handle; 14 15 pl_parampl ("BITMAPSIZE", "300x300"); 16 17 if ((handle = pl_newpl ("X", stdin, stdout, stderr)) < 0) 18 { 19 fprintf (stderr, "Couldn't create Plotter\n"); 20 return EXIT_FAILURE; 21 } 22 23 pl_selectpl (handle); 24 25 if (pl_openpl () < 0) 26 { 27 fprintf (stderr, "Couldn't open Plotter\n"); 28 } 29 30 pl_fspace (-2.0, -2.0, 2.0, 2.0); 31 pl_bgcolorname ("white"); 32 33 make_plot (); 34 35 if (pl_closepl () < 0) 36 { 37 fprintf (stderr, "Couldn't close Plotter\n"); 38 return EXIT_FAILURE; 39 } 40 pl_selectpl (0); 41 42 if (pl_deletepl (handle) < 0) 43 { 44 fprintf (stderr, "Couldn't delete Plotter\n"); 45 return EXIT_FAILURE; 46 } 47 48 return EXIT_SUCCESS; 49 } 50 51 void 52 make_plot (void) 53 { 54 pl_erase (); 55 56 57 pl_pencolorname ("red"); 58 pl_flinewidth(0.05); 59 pl_fillcolorname ("yellow"); 60 61 pl_fcircle(0, 0, 0.8); 62 int i; 63 double x, y; 64 int n = 10; 65 for (i=0; i<n; i++) { 66 pl_filltype(i%2); 67 x = 1.5 * cos(2*M_PI/n *i); 68 y = 1.5 * sin(2*M_PI/n *i); 69 pl_fcircle(x, y, 0.4); 70 pl_fline(0, 0, x, y); 71 } 72 }
Code description
- 15
- Set Ploter parameters
- 17
- Create an X Ploter with the specified parameters
- 23
- Select plotter for use
- 30
- Set the user coordinate system
- 33
- Call the drawing function
- 35
- Close plotter
- 40
- Select the default plotter
- 42
- Delete plotter
- 54
- Erase window
- 66
- Alternate filltype to make filled and empty circles