home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / vopl.tar.Z / vopl.tar / vopl / examples / cex2.c < prev    next >
C/C++ Source or Header  |  1999-10-16  |  2KB  |  134 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.  *    Another very simple test program for vopl.
  12.  *
  13.  *     This one also draws a graph of y = sin(x) 0 <= x <= 2 * PI
  14.  *    but shows some of the axis and range setting stuff
  15.  */
  16. main()
  17. {
  18.     int    i;
  19.     char    device[30];
  20.     float    t, dt;
  21.  
  22. /*
  23.  *    Get VOGLE device
  24.  */
  25.     printf("Enter VOGLE device: ");
  26.     gets(device);
  27.  
  28. /*
  29.  *    Generate the points
  30.  */
  31.     t = 0.0;
  32.     dt = 2 * PI / N;
  33.  
  34.     for (i = 0; i != N; i++) {
  35.         x[i] = t;
  36.         y[i] = sin(t);
  37.         t = t + dt;
  38.     }
  39.  
  40. /*
  41.  *    Set the X-scaling to be absolute 0 - 10 (ie no auto-scaling)
  42.  */
  43.     range(0.0, 10.0, 'x');
  44. /*
  45.  *    Autoscale the Y-axis
  46.  */
  47.     adjustscale(y, N, 'y');
  48. /*
  49.  *    Anyone for some axis titles?
  50.  */
  51.     axistitle("This one's for you", 'x');
  52.     axistitle("This one's for me", 'y');
  53. /*
  54.  *    As we are now about to do some graphics we initialise VOGLE
  55.  *    and clear to BLACK
  56.  */
  57.     vinit(device);
  58.     color(0);
  59.     clear();
  60. /*
  61.  *    Now set the color to GREEN
  62.  */
  63.     color(2);
  64.  
  65. /*
  66.  *    Draw the default set of axes (in GREEN)
  67.  */
  68.     drawaxes2();
  69. /*
  70.  *    Set color to RED
  71.  */
  72.     color(1);
  73. /*
  74.  *    Draw the Graph
  75.  */
  76.     plot2(x, y, N);
  77. /*
  78.  *    Wait around a bit
  79.  */
  80.     getkey();
  81. /*
  82.  *    Now draw a little one in the top right hand corner
  83.  *    by reseting the VOGLE viewport.
  84.  */
  85.     viewport(0.0, 1.0, 0.0, 1.0);
  86. /*
  87.  *    Draw it again, but do the plot first (in BLUE) then the axes
  88.  *    (in YELLOW)
  89.  */
  90.     color(4);
  91.     plot2(x, y, N);
  92.     color(3);
  93.     drawaxes2();
  94. /*
  95.  *    Hang around again
  96.  */
  97.     getkey();
  98. /*
  99.  *    Clear it all away
  100.  */
  101.     color(0);
  102.     clear();
  103. /*
  104.  *    Reset the viewport to be a "long skinny one"
  105.  */
  106.     viewport(-1.0, 1.0, -0.5, 0.5);
  107. /*
  108.  *    Autoscale the X-axis again by first setting a ridicuous scale with
  109.  *    range that adjustscale will change.
  110.  */
  111.     range(1000.0, -1000.0, 'x');
  112.     adjustscale(x, N, 'x');
  113. /*
  114.  *    Change the X-axis title
  115.  */
  116.     axistitle("Blark Bonk Bloot", 'x');
  117. /*
  118.  *    And draw it all again...
  119.  */
  120.     color(5);
  121.     drawaxes2();
  122.     color(6);
  123.     plot2(x, y, N);
  124. /*
  125.  *    Hang around again
  126.  */
  127.     getkey();
  128. /*
  129.  *    Bugger off...
  130.  */
  131.  
  132.     vexit();
  133. }
  134.