Ploting circles and lines

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 }

Copyright 2006 Roman Putanowicz

Email: putanowr at twins.pk.edu.pl

Last Modified: Thu, 29 Jun 2006 18:04:07 CEST

Made with PubTal 3.1.3