home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / EXAMPLES / POLY.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  2KB  |  128 lines

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4. /*
  5.  *    An array of points for a polygon
  6.  */
  7. static float    parray[][3] = {
  8.     {-8.0, -8.0, 0.0},
  9.     {-5.0, -8.0, 0.0},
  10.     {-5.0, -5.0, 0.0},
  11.     {-8.0, -5.0, 0.0}
  12. };
  13.  
  14. /*
  15.  * drawpoly
  16.  *
  17.  *    draw some polygons
  18.  */
  19. drawpoly()
  20. {
  21.     color(YELLOW);
  22.  
  23.     /*
  24.      * Draw a polygon using poly, parray is our array of
  25.      * points and 4 is the number of points in it.
  26.      */
  27.     poly(4, parray);
  28.  
  29.     color(GREEN);
  30.  
  31.     /*
  32.      * Draw a 5 sided figure by using move, draw and closepoly.
  33.      */
  34.     makepoly();
  35.         move(0.0, 0.0, 0.0);
  36.         draw(3.0, 0.0, 0.0);
  37.         draw(3.0, 4.0, 0.0);
  38.         draw(-1.0, 5.0, 0.0);
  39.         draw(-2.0, 2.0, 0.0);
  40.     closepoly();
  41.  
  42.     color(MAGENTA);
  43.  
  44.     /*
  45.      * draw a sector representing a 1/4 circle
  46.      */
  47.     sector(1.5, -7.0, 3.0, 0.0, 90.0);
  48.  
  49.     getkey();
  50. }
  51.  
  52. /*
  53.  * Using polygons, hatching, and filling.
  54.  */
  55. main()
  56. {
  57.     char device[10];
  58.  
  59.     fprintf(stderr,"Enter output device: ");
  60.     gets(device);
  61.  
  62.     vinit(device);
  63.  
  64.     color(BLACK);        /* clear to bleck */
  65.     clear();
  66.  
  67.     /*
  68.      * world coordinates are now in the range -10 to 10
  69.      * in x, y, and z. Note that positive z is towards us.
  70.      */
  71.     ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);
  72.  
  73.     color(YELLOW);
  74.  
  75.     /*
  76.      * write out the string "Polygon from poly()" in the
  77.      * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
  78.      * 0.5 units high.
  79.      */
  80.     boxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()");
  81.  
  82.     color(GREEN);
  83.  
  84.     /*
  85.      * write out a scaled string starting at (0.0, 6.0)
  86.      */
  87.     boxtext(0.0, 6.0, 4.0, 0.5, "Polygon from move()/ draw()");
  88.  
  89.     color(MAGENTA);
  90.  
  91.     /*
  92.      * write out a scaled string starting at (0.0, 6.0)
  93.      */
  94.     boxtext(3.5, -3.5, 1.9, 0.5, "Sector");
  95.  
  96.     drawpoly();        /* draw some polygons */
  97.  
  98.     /*
  99.      * turn on polygon hatching
  100.      */
  101.     polyhatch(1);
  102.     hatchang(45.0);
  103.     hatchpitch(0.3);
  104.  
  105.     /*
  106.      *  Rotate 20 degrees around x and 30 around y
  107.      */
  108.     rotate(20.0, 'x');
  109.     rotate(30.0, 'y');
  110.  
  111.     drawpoly();        /* draw some polygons wth hatching */
  112.  
  113.     /*
  114.      * turn on polygon filling - this automatically turns off hatching
  115.      */
  116.     polyfill(1);
  117.  
  118.     /*
  119.      *  Do another set of rotations.
  120.      */
  121.     rotate(20.0, 'x');
  122.     rotate(30.0, 'y');
  123.  
  124.     drawpoly();        /* draw some polygons with filling */
  125.  
  126.     vexit();
  127. }
  128.