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

  1. /* remoire.c -- adds palette remapping to moire.c      */
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <graph.h>
  6. #define ESC '\033'
  7. #define MAXCOLORS 64
  8. #define PALCOLORS 16
  9. long Ega_to_vga(int);
  10.  
  11. main (argc, argv)
  12. int argc;
  13. char *argv[];
  14. {
  15.     struct videoconfig vc;
  16.     unsigned int col, row;
  17.     long colors[MAXCOLORS];
  18.     long palette[PALCOLORS];
  19.     int index;
  20.     int shift = 1;
  21.     int firstcol, firstrow, lastrow, lastcol;
  22.     int mode = _ERESCOLOR;
  23.  
  24.  
  25.     if (argc > 1)
  26.         mode = atoi(argv[1]);
  27.  
  28.     if (_setvideomode(mode) == 0)
  29.         {
  30.         printf("Can't do that mode.\n");
  31.         exit(1);
  32.         }
  33.     /* Create array of all 64 color values. */
  34.     for (index = 0; index < MAXCOLORS; index++)
  35.         colors[index] = Ega_to_vga(index);
  36.     /* Create array of 16 palette choices. */
  37.     for (index = 0; index < PALCOLORS; index++)
  38.         palette[index] = colors[index];
  39.     _remapallpalette(palette);
  40.     _getvideoconfig(&vc);
  41.     firstcol = vc.numxpixels / 5;
  42.     firstrow = vc.numypixels / 5;
  43.     lastcol = 4 * vc.numxpixels / 5;
  44.     lastrow = 4 * vc.numypixels / 5;
  45.  
  46.     for (col = firstcol; col <= lastcol; ++col)
  47.         {
  48.         for (row = firstrow; row <= lastrow; ++row)
  49.             {
  50.             _setcolor(((row * row + col * col) / 10)
  51.                        % vc.numcolors);
  52.             _setpixel(col, row);
  53.             }
  54.         }
  55.     _settextposition(1, 1);
  56.     _outtext("Type a key to stop or start.");
  57.     _settextposition(2, 1);
  58.     _outtext("Type [Esc] while paused to quit.");
  59.     do
  60.         {
  61.         while (!kbhit())
  62.             {
  63.             /*  Set palette array to new color values. */
  64.             for (index = 1; index < PALCOLORS; index++)
  65.                 palette[index] = (colors[(index + shift)
  66.                                   % MAXCOLORS]);
  67.             _remapallpalette(palette);
  68.             shift++;
  69.              }
  70.          getch();  /* pause until key is typed */
  71.         }  while (getch() != ESC);
  72.  
  73.     _setvideomode(_DEFAULTMODE);  /* reset orig. mode */
  74. }
  75.  
  76. long Ega_to_vga(egacolor)
  77. int egacolor;       /* ega color value */
  78. {
  79.     static long vgavals[6] = {0x2A0000L, 0x002A00L, 0x00002AL,
  80.                               0x150000L, 0x001500L, 0x000015L};
  81.     long vgacolor = 0L; /* vga color value */
  82.     int bit;
  83.  
  84.     for (bit = 0; bit < 6; bit++)
  85.         vgacolor += ((egacolor >> bit) &1) * vgavals[bit];
  86.     return (vgacolor);
  87. }
  88.