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

  1. /*  col256.c  -- show 256 colors in mode 19             */
  2. /* If you load graphics.qlb, no program list is needed. */
  3.  
  4. #include <stdio.h>
  5. #include <graph.h>
  6. #include <conio.h>
  7. #define ESC '\033'
  8. #define ROWS 16
  9. #define COLS 16
  10. main()
  11. {
  12.     struct videoconfig vc;
  13.     int mode = _MRES256COLOR;
  14.     short xmax, ymax;           /* screen size */
  15.     short xcs[ROWS][COLS];      /* coordinates of the */
  16.     short ycs[ROWS][COLS];      /* 256 rectangles     */
  17.     short row, col;
  18.  
  19.  
  20.     if (_setvideomode(mode) == 0)
  21.         {
  22.         fprintf(stderr, "%d mode not supported\n", mode);
  23.         exit(1);
  24.         }
  25.     _getvideoconfig(&vc);
  26.  
  27.     xmax = vc.numxpixels - 1;
  28.     ymax = vc.numypixels - 1;
  29.  
  30.     /* Compute an interior point for each rectangle. */
  31.     for (col = 0; col < COLS; col++)
  32.         for (row = 0; row < ROWS; row++)
  33.             {
  34.             xcs[row][col] =  col * xmax / COLS + 5;
  35.             ycs[row][col] =  row * ymax / ROWS + 5;
  36.  
  37.             }
  38.  
  39.     /* draw outside boundary */
  40.     _setcolor(1);
  41.     _rectangle(_GBORDER, 0, 0, xmax, ymax);
  42.  
  43.     /* draw gridwork */
  44.     for (col = 1; col < COLS ; col++)
  45.         {
  46.         _moveto(col * (xmax + 1) / COLS, 0);
  47.         _lineto(col * (xmax + 1) / COLS, ymax);
  48.         }
  49.     for (row = 1; row < ROWS;  row++)
  50.         {
  51.         _moveto(0, row * (ymax + 1) / ROWS);
  52.         _lineto(xmax, row * (ymax + 1) / ROWS);
  53.         }
  54.  
  55.     /*  fill in rectangles with palette colors */
  56.     for (col = 0; col < COLS; col++)
  57.         for (row = 0; row < ROWS; row++)
  58.             {
  59.             _setcolor(row * ROWS + col);
  60.             _floodfill(xcs[row][col], ycs[row][col],1);
  61.             }
  62.  
  63.     /* terminate program */
  64.     getch();
  65.     _setvideomode(_DEFAULTMODE);
  66. }
  67.