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

  1. /*   moire.c -- variation on dots.c                   */
  2. /* If you load graphics.qlb, no program list is needed*/
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <graph.h>
  7. #define ESC '\033'
  8. #define BKCOLS 8      /* number of background colors */
  9. #define PALNUM 4      /* number of palettes */
  10. long Bkcolors[BKCOLS] = {_BLACK, _BLUE, _GREEN, _CYAN, _RED,
  11.                          _MAGENTA, _BROWN, _WHITE};
  12. main (argc, argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.      struct videoconfig vc;
  17.      unsigned int col, row;
  18.      short color = 0;
  19.      int bkc_index = 1;  /* blue background */
  20.      short palette = 0;  /* red, green, brown */
  21.      int firstcol, firstrow, lastrow, lastcol;
  22.      int mode = _MRES4COLOR;
  23.      int ch;
  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.      _getvideoconfig(&vc);
  34.      firstcol = vc.numxpixels / 5;
  35.      firstrow = vc.numypixels / 5;
  36.      lastcol = 4 * vc.numxpixels / 5;
  37.      lastrow = 4 * vc.numypixels / 5;
  38.      _selectpalette(palette);
  39.      _setbkcolor (Bkcolors[bkc_index]);
  40.      for (col = firstcol; col <= lastcol; ++col)
  41.           {
  42.  
  43.           for (row = firstrow; row <= lastrow; ++row)
  44.                {
  45.                _setcolor(((row*row + col*col)/10)%vc.numcolors);
  46.                _setpixel(col, row);
  47.                }
  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.