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

  1. /* dots.c -- illustrates the _setcolor(), _setpixel(), */
  2. /*           and _selectpalette() functions from the   */
  3. /*           QuickC graphics library                   */
  4. /* If you load graphics.qlb, no program list is needed */
  5.  
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <graph.h>
  10. #define ESC '\033'
  11. #define BKCOLS 8      /* number of background colors */
  12. #define PALNUM 4      /* number of palettes */
  13. long Bkcolors[BKCOLS] = {_BLACK, _BLUE, _GREEN, _CYAN, _RED,
  14.                          _MAGENTA, _BROWN, _WHITE};
  15. main (argc, argv)
  16. int argc;
  17. char *argv[];
  18. {
  19.      struct videoconfig vc;
  20.      unsigned int col, row;
  21.      short color = 0;
  22.      int bkc_index = 1;  /* blue background */
  23.      short palette = 0;  /* red, green, brown */
  24.      int firstcol, firstrow, lastrow, lastcol;
  25.      int mode = _MRES4COLOR;
  26.      int ch;
  27.  
  28.      if (argc > 1)
  29.           mode = atoi(argv[1]);
  30.  
  31.      if (_setvideomode(mode) == 0)
  32.      {
  33.           printf("Can't do that mode.\n");
  34.           exit(1);
  35.      }
  36.      _getvideoconfig(&vc);
  37.      firstcol = vc.numxpixels / 5;
  38.      firstrow = vc.numypixels / 5;
  39.      lastcol = 4 * vc.numxpixels / 5;
  40.      lastrow = 4 * vc.numypixels / 5;
  41.      _selectpalette(palette);
  42.      _setbkcolor (Bkcolors[bkc_index]);
  43.      for (col = firstcol; col <= lastcol; ++col)
  44.      {
  45.           _setcolor((++color / 3) % vc.numcolors);
  46.           for (row = firstrow; row <= lastrow; ++row)
  47.                _setpixel(col, row);
  48.      }
  49.      while ((ch = getch()) != ESC)
  50.      {
  51.           if (ch == 'p')
  52.                 _selectpalette(++palette % PALNUM);
  53.           else if (ch == 'b')
  54.                 _setbkcolor(Bkcolors[++bkc_index % BKCOLS]);
  55.      }
  56.      _setvideomode(_DEFAULTMODE);  /* reset orig. mode */
  57. }
  58.