home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap15 / rings.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-07  |  2.8 KB  |  91 lines

  1. /*  rings.c -- shoots colored rings                   */
  2. /*  This program illustrates _remapallpalette() and   */
  3. /*  how it can be used to produce the appearance of   */
  4. /*  motion. The program is intended for EGA modes 13, */
  5. /*  14, and 16.                                       */
  6. /* Program list: rings.c                              */
  7. /* If you load graphics.qlb, no program list is needed*/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12. #include <graph.h>
  13. #define ESC '\033'
  14.  
  15. long Colors[16] = {_BLACK, _BLUE, _GREEN, _CYAN,
  16.                  _RED, _MAGENTA, _BROWN, _WHITE,
  17.                  _GRAY, _LIGHTBLUE, _LIGHTGREEN,
  18.                  _LIGHTCYAN, _LIGHTRED, _LIGHTMAGENTA,
  19.                  _LIGHTYELLOW,_BRIGHTWHITE };
  20.  
  21. main(argc, argv)
  22. int argc;
  23. char *argv[];
  24. {
  25.     struct videoconfig vc;
  26.     float aspect;
  27.     short xmax, ymax;
  28.     long int newpalette[16];
  29.     long int temp;
  30.     int index;
  31.     int hot1 = 1;  /* first colored ring  */
  32.     int hot2 = 8;  /* second colored ring */
  33.     int mode = _ERESCOLOR;
  34.     int ch;
  35.  
  36.     if (argc > 1)
  37.         mode = atoi(argv[1]);
  38.     if (mode < 13)
  39.     {
  40.         fprintf(stderr,"Requires EGA or VGA mode\n");
  41.         exit(1);
  42.     }
  43.     if (_setvideomode(mode) == 0)
  44.     {
  45.         fprintf(stderr,"% d mode unavailable\n", mode);
  46.         exit(2);
  47.     }
  48.     _getvideoconfig(&vc);
  49.     _setlogorg(vc.numxpixels / 2 - 1, vc.numypixels / 2 - 1);
  50.     aspect = (10.0 * vc.numypixels) / (6.5 * vc.numxpixels);
  51.     ymax = vc.numypixels / 2 - 2;
  52.     xmax = ymax / aspect;
  53.     for (index = 2; index < 16; index++)
  54.         newpalette[index] = _LIGHTBLUE;
  55.     newpalette[0] = _GRAY;
  56.     newpalette[hot1] = _RED;
  57.     newpalette[hot2] = _LIGHTRED;
  58.     _remapallpalette(newpalette);  /* set initial palette */
  59.     _setcolor(1);
  60.     _ellipse(_GFILLINTERIOR, -xmax, -ymax, xmax, ymax);
  61.     /* draw concentric circles */
  62.     for (index = 2; index < 16; index++)
  63.         {
  64.         xmax /= 1.4;
  65.         ymax /= 1.4;
  66.         _setcolor(index);
  67.         _ellipse(_GFILLINTERIOR, -xmax, -ymax, xmax, ymax);
  68.         }
  69.     do
  70.         {
  71.         while (!kbhit())
  72.             {
  73.             temp = newpalette[15];
  74.             for(index = 15; index > 1; index--)
  75.                 newpalette[index] = newpalette[index - 1];
  76.             newpalette[1] = temp;
  77.             _remapallpalette(newpalette);
  78.             hot1 = hot1 % 15 + 1;  /* index of colored ring */
  79.             hot2 = hot2 % 15 + 1;
  80.             }
  81.         ch = getch();
  82.         if (ch > '1' && ch < '8')  /* reassign colors */
  83.             {
  84.             newpalette[hot1] = Colors[ ch - '0'];
  85.             newpalette[hot2] = Colors[ ch - '0' + 8];
  86.             }
  87.          } while (ch != ESC);
  88.     _clearscreen(_GCLEARSCREEN);
  89.     _setvideomode(_DEFAULTMODE);
  90. }
  91.