home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / vopl.tar.Z / vopl.tar / vopl / examples / cex3.c < prev    next >
C/C++ Source or Header  |  1999-10-16  |  2KB  |  133 lines

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