home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vopl / glvopl.lha / glvopl / examples / cex3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-07  |  1.9 KB  |  138 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #ifdef SGI_GL
  5. #include "gl.h"
  6. #include "device.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #define    N    10
  13.  
  14. /*
  15.  *    Another simple test program for vopl.
  16.  *
  17.  *     This one tries to show the various "fit" options
  18.  */
  19. main()
  20. {
  21.     static float    x[N] = {
  22.             1.0, 2.0, 3.0, 6.0,
  23.             17.0, 19.0, 23.0, 45.0,
  24.             50.0, 56.0
  25.     };
  26.     static float    y[N] = {
  27.             1.0, 3.0, 5.0, 9.0,
  28.             17.0, 45.0, 23.0, 99.0,
  29.             50.0, 20.0
  30.     };
  31.  
  32.     short    val;
  33.     Screencoord     left, right, bottom, top;
  34.  
  35. /*
  36.  *    First we'll do a linear least square fit.
  37.  */
  38.     fit(2);
  39.     degree(1);
  40. /*
  41.  *    Adjust the scaling according to x and y arrays
  42.  */
  43.     adjustscale(x, N, 'x');
  44.     adjustscale(y, N, 'y');
  45. /*
  46.  *    Give it a title
  47.  */
  48.     graphtitle("Linear Least square fit");
  49. /*
  50.  *    As we are now about to do some graphics we initialise VOGLE
  51.  *    and clear to BLACK
  52.  */
  53.     hfont("futura.m");
  54.     winopen("VOPL");
  55.     qdevice(KEYBD);
  56.     color(0);
  57.     clear();
  58. /*
  59.  *    Draw the title in CYAN
  60.  */
  61.     color(6);
  62.     drawtitle();
  63. /*
  64.  *    Now set the color to GREEN
  65.  */
  66.     color(2);
  67.  
  68. /*
  69.  *    Draw the default set of axes (in GREEN)
  70.  */
  71.     drawaxes2();
  72. /*
  73.  *    Set color to RED
  74.  */
  75.     color(1);
  76. /*
  77.  *    Change to the "markers" font and set the current marker string
  78.  */
  79.     hfont("markers");
  80.     marker("a");
  81. /*
  82.  *    Draw the Graph
  83.  */
  84.     plot2(x, y, N);
  85. /*
  86.  *    Wait around a bit
  87.  */
  88.     qread(&val);
  89. /*
  90.  *    Now we'll do a second order fit.
  91.  */
  92.     degree(2);
  93.     graphtitle("Second order least square fit");
  94.  
  95.     color(0);
  96.     clear();
  97.  
  98.     color(7);
  99.     plot2(x, y, N);
  100. /*
  101.  *    Change back to the "text" type font to draw the title and axes
  102.  */
  103.     hfont("futura.m");
  104.  
  105.     color(3);
  106.     drawaxes2();
  107.  
  108.     color(6);
  109.     drawtitle();
  110. /*
  111.  *     Wait a bit
  112.  */
  113.     qread(&val);
  114. /*
  115.  *    Now do a Cubic spline fit (cardinal spline for this one)
  116.  */
  117.     fit(3);
  118.     
  119.     color(0);
  120.     clear();
  121.  
  122.     color(5);
  123.     drawaxes2();
  124.  
  125.     graphtitle("Cardinal Cubic Spline Fit");
  126.     color(6);
  127.     drawtitle();
  128.  
  129. /*
  130.  *    Note, we haven't changed to the Marker font here
  131.  */
  132.     plot2(x, y, N);
  133.  
  134.     qread(&val);
  135.  
  136.     gexit();
  137. }
  138.