home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / POLY.C < prev    next >
Text File  |  1993-05-28  |  2KB  |  124 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.     prefsize(250, 250);
  58.     vinit("mswin");
  59.  
  60.     color(BLACK);        /* clear to bleck */
  61.     clear();
  62.  
  63.     /*
  64.      * world coordinates are now in the range -10 to 10
  65.      * in x, y, and z. Note that positive z is towards us.
  66.      */
  67.     ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);
  68.  
  69.     color(YELLOW);
  70.  
  71.     /*
  72.      * write out the string "Polygon from poly()" in the
  73.      * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
  74.      * 0.5 units high.
  75.      */
  76.     boxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()");
  77.  
  78.     color(GREEN);
  79.  
  80.     /*
  81.      * write out a scaled string starting at (0.0, 6.0)
  82.      */
  83.     boxtext(0.0, 6.0, 4.0, 0.5, "Polygon from move()/ draw()");
  84.  
  85.     color(MAGENTA);
  86.  
  87.     /*
  88.      * write out a scaled string starting at (0.0, 6.0)
  89.      */
  90.     boxtext(3.5, -3.5, 1.9, 0.5, "Sector");
  91.  
  92.     drawpoly();        /* draw some polygons */
  93.  
  94.     /*
  95.      * turn on polygon hatching
  96.      */
  97.     polyhatch(1);
  98.     hatchang(45.0);
  99.     hatchpitch(0.3);
  100.  
  101.     /*
  102.      *  Rotate 20 degrees around x and 30 around y
  103.      */
  104.     rotate(20.0, 'x');
  105.     rotate(30.0, 'y');
  106.  
  107.     drawpoly();        /* draw some polygons wth hatching */
  108.  
  109.     /*
  110.      * turn on polygon filling - this automatically turns off hatching
  111.      */
  112.     polyfill(1);
  113.  
  114.     /*
  115.      *  Do another set of rotations.
  116.      */
  117.     rotate(20.0, 'x');
  118.     rotate(30.0, 'y');
  119.  
  120.     drawpoly();        /* draw some polygons with filling */
  121.  
  122.     vexit();
  123. }
  124.