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

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "vopl.h"
  4.  
  5. #define PI    3.14159265358979
  6. #define    N    300
  7.  
  8. float    x[N], y[N];
  9.  
  10. /*
  11.  *    A very simple test program for vopl.
  12.  *
  13.  *     This one draws a graph of y = sin(x) 0 <= x <= 2 * PI
  14.  */
  15. main()
  16. {
  17.     float    t, dt;
  18.     char    device[30];
  19.     int    i;
  20.  
  21. /*
  22.  *    Get VOGLE device
  23.  */
  24.     printf("Enter VOGLE device: ");
  25.     gets(device);
  26.  
  27. /*
  28.  *    Generate the points
  29.  */
  30.     t = 0.0;
  31.     dt = 2 * PI / N;
  32.  
  33.     for (i = 0; i != N; i++) {
  34.         x[i] = t;
  35.         y[i] = sin(t);
  36.         t = t + dt;
  37.     }
  38.  
  39. /*
  40.  *    Adjust the scaling according to x and y arrays
  41.  */
  42.     adjustscale(x, N, 'x');
  43.     adjustscale(y, N, 'y');
  44. /*
  45.  *    As we are now about to do some graphics we initialise VOGLE
  46.  *    and clear to BLACK
  47.  */
  48.     vinit(device);
  49.     color(0);
  50.     clear();
  51. /*
  52.  *    Now set the color to GREEN
  53.  */
  54.     color(2);
  55.  
  56. /*
  57.  *    Draw the default set of axes (in GREEN)
  58.  */
  59.     drawaxes2();
  60. /*
  61.  *    Set color to RED
  62.  */
  63.     color(1);
  64. /*
  65.  *    Draw the Graph
  66.  */
  67.     plot2(x, y, N);
  68. /*
  69.  *    Wait around a bit
  70.  */
  71.     getkey();
  72. /*
  73.  *    Now draw a little one in the top right hand corner
  74.  *    by reseting the VOGLE viewport.
  75.  */
  76.     viewport(0.0, 1.0, 0.0, 1.0);
  77. /*
  78.  *    Draw it again, but do the plot first (in BLUE) then the axes
  79.  *    (in YELLOW)
  80.  */
  81.     color(4);
  82.     plot2(x, y, N);
  83.     color(3);
  84.     drawaxes2();
  85. /*
  86.  *    Hang around again
  87.  */
  88.     getkey();
  89. /*
  90.  * bugger off
  91.  */
  92.     vexit();
  93. }
  94.