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

  1. /* arrow.c -- fill inside and outside of a line       */
  2. /*            drawing                                 */
  3. /* If you load graphics.qlb, no program list is needed*/
  4.  
  5. #include <stdio.h>
  6. #include <graph.h>
  7. #include <conio.h>
  8. #define ESC '\033'
  9. #define BKCOLS 16   /* use 16 background colors */
  10. long Bkcolors[BKCOLS] = {_BLACK, _BLUE, _GREEN, _CYAN,
  11.                  _RED, _MAGENTA, _BROWN, _WHITE,
  12.                  _GRAY, _LIGHTBLUE, _LIGHTGREEN,
  13.                  _LIGHTCYAN, _LIGHTRED, _LIGHTMAGENTA,
  14.                  _LIGHTYELLOW,_BRIGHTWHITE };
  15. char Mask[8] = {0x90, 0x68, 0x34, 0x19, 0x19, 0x34, 0x68,
  16.                 0x90};
  17. char Outmask[8] = {0xff, 0x80, 0x80, 0x80, 0xff, 0x08, 0x08,
  18.                    0x08};
  19. main(argc, argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.     struct videoconfig vc;
  24.     int mode = _MRES4COLOR;
  25.     float x1, y1, x2, y2, x3, y3, y4, x5, y5;
  26.     long bk = _BLUE;
  27.  
  28.     if (argc > 1)
  29.         mode = atoi(argv[1]);
  30.     if (_setvideomode(mode) == 0)
  31.         {
  32.         printf("Can't set mode %d.\n", mode);
  33.         exit(1);
  34.         }
  35.     _getvideoconfig(&vc);
  36.  
  37.     x1 = 0.1 * vc.numxpixels;
  38.     x2 = 0.7 * vc.numxpixels;
  39.     x3 = 0.6 * vc.numxpixels;
  40.     x5 = 0.9 * vc.numxpixels;
  41.     y1 = 0.45 * vc.numypixels;
  42.     y2 = 0.55 * vc.numypixels;
  43.     y3 = 0.3 * vc.numypixels;
  44.     y4 = 0.7 * vc.numypixels;
  45.     y5 = 0.5 * vc.numypixels;
  46.     _selectpalette(0);
  47.     _setcolor(1);
  48.     _moveto(x1, y1);
  49.     _lineto(x2, y1);
  50.     _lineto(x3, y3);
  51.     _lineto(x5, y5);
  52.     _lineto(x3, y4);
  53.     _lineto(x2, y2);
  54.     _lineto(x1, y2);
  55.     _lineto(x1, y1);
  56.     _setcolor(2);
  57.     _setfillmask(Mask);
  58.     _floodfill(x2, y5, 1) ;
  59.     _setcolor(3);
  60.     _setfillmask(Outmask);     /* restores default mask */
  61.     _floodfill(5, 5, 1) ;
  62.     _settextcolor(1);
  63.     _settextposition(23, 0);
  64.     _outtext("Press <enter> to change background.");
  65.     _settextposition(24, 0);
  66.     _outtext("Press <esc> to end.");
  67.     while (getch() != ESC)
  68.         _setbkcolor(Bkcolors[++bk % BKCOLS]);
  69.     _setvideomode(_DEFAULTMODE);
  70. }
  71.