home *** CD-ROM | disk | FTP | other *** search
/ MS DOS Archives 1 / MS-DOS_Archives_Volume_One_Walnut_Creek.iso / msdos / graphics / grafxlib.arc / GRAFEX2.C < prev    next >
C/C++ Source or Header  |  1987-08-31  |  2KB  |  82 lines

  1. /*
  2.  * grafex2.c
  3.  *
  4.  * the same example program, done with halo calls
  5.  *
  6.  * compile with:
  7.  *  MSC - msc grafex2;
  8.  *        link grafex2,,,grafix
  9.  *
  10.  *  TC  - tcc grafex2 <grafix lib directory>\grafix.lib
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <conio.h>
  15. #include <math.h>
  16. #include "graf.h"
  17. #include "halo.h"
  18.  
  19. #define pi 3.1415926
  20. #define MAXVERT 100
  21.  
  22. main()
  23. {
  24.   int n, i, j, d;
  25.   float x1, y1, x2, y2;
  26.   int c;
  27.   struct g_info inf;
  28.   struct {
  29.     float x, y;
  30.   } vert[MAXVERT];
  31.  
  32.   printf("n: ");
  33.   scanf("%d", &n);
  34.   if (n < 2 || n > MAXVERT) {
  35.     printf("Oop Ack!\n");
  36.     exit(1);
  37.   }
  38.  
  39.   g_init(0);
  40.   g_open(CGA_320);    /* use 4-color mode on CGA. on an EGA, the mode   */
  41.             /* parameter is ignored and 16-color mode is used */
  42.   g_info(&inf);
  43.   halo_init();
  44.  
  45.   x1 = -3;        /* lower left corner */
  46.   y1 = -3;
  47.   x2 = 3;        /* upper right corner */
  48.   y2 = 3;
  49.   setworld(&x1, &y1, &x2, &y2);
  50.  
  51. /* space n vertices equally on an ellipse that fits nicely on the screen */
  52.  
  53.   for (i=0; i<n; i++) {
  54.     vert[i].x = 2.0*sin(2*pi/n*i);
  55.     vert[i].y = 2.0*cos(2*pi/n*i);
  56.   }
  57.  
  58. /*
  59.  * draw the figure. the colors are selected so that points that are the
  60.  * same distance from each other on the ellipse have the same color.
  61.  */
  62.  
  63.   for (i=0; i<n; i++)
  64.     for (j=i+1; j<n; j++) {
  65.       d = j-i;
  66.       if (d > n/2) d = n - d;
  67.       c = (float)d/(n/2+1)*inf.colormax + 1;
  68.       setcolor(&c);
  69.       movabs(&vert[i].x, &vert[i].y);
  70.       lnabs(&vert[j].x, &vert[j].y);
  71.     }
  72.  
  73. /* wait... */
  74.  
  75.   g_writestr(0, 0, "Press any key...", 1, -1);
  76.   getch();
  77.  
  78. /* and clean up. */
  79.  
  80.   g_close();
  81. }
  82.