home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / graphics / fill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  2.3 KB  |  67 lines

  1. /* FILL.C illustrates color, filling, and linestyle functions including:
  2.  *    _setlinestyle      _setfillmask       _setcolor
  3.  *    _getlinestyle      _floodfill
  4.  *
  5.  * The _getfillmask function is not shown, but its use is similar to
  6.  * _getlinestyle.
  7.  */
  8.  
  9. #include <conio.h>
  10. #include <graph.h>
  11. #include <time.h>
  12. #include <stdlib.h>
  13.  
  14. main()
  15. {
  16.     short x, y, xinc, yinc, xwid, ywid;
  17.     unsigned char fill[8];
  18.     struct videoconfig vc;
  19.     unsigned seed = (unsigned)time( 0L );   /* Different seed each time */
  20.     short i, color, mode = _VRES16COLOR;
  21.  
  22.     while( !_setvideomode( mode ) )         /* Find best graphics mode  */
  23.         mode--;
  24.     if (mode == _TEXTMONO )
  25.         exit( 1 );                          /* No graphics available    */
  26.     _getvideoconfig( &vc );
  27.  
  28.     xinc = vc.numxpixels / 8;               /* Size variables to mode   */
  29.     yinc = vc.numxpixels / 8;
  30.     xwid = (xinc / 2) - 4;
  31.     ywid = (yinc / 2) - 4;
  32.  
  33.     /* Draw circles and lines with different patterns. */
  34.     for( x = xinc; x <= (vc.numxpixels - xinc); x += xinc )
  35.     {
  36.         for( y = yinc; y <= (vc.numypixels - yinc); y += yinc )
  37.         {
  38.             /* Vary random seed, randomize fill and color. */
  39.             srand( seed = (seed + 431) * 5 );
  40.             for( i = 0; i < 8; i++ )
  41.                 fill[i] = rand();
  42.             _setfillmask( fill );
  43.             color = (rand() % vc.numcolors) + 1;
  44.             _setcolor( color );
  45.  
  46.             /* Draw ellipse and fill with random color. */
  47.             _ellipse( _GBORDER, x - xwid, y - ywid, x + xwid, y + ywid );
  48.             _setcolor( (rand() % vc.numcolors) + 1 );
  49.             _floodfill( x, y, color );
  50.  
  51.             /* Draw vertical and horizontal lines. Vertical line style
  52.              * is opposite of (not) horizontal style. Since lines are
  53.              * overdrawn with several linestyles, this has the effect of
  54.              * combining colors and styles.
  55.              */
  56.             _setlinestyle( rand() );
  57.             _moveto( 0, y + ywid + 4 );
  58.             _lineto( vc.numxpixels - 1, y + ywid + 4 );
  59.             _setlinestyle( ~_getlinestyle() );
  60.             _moveto( x + xwid + 4, 0 );
  61.             _lineto( x + xwid + 4, vc.numypixels - 1 );
  62.         }
  63.     }
  64.     getch();
  65.     exit( !_setvideomode( _DEFAULTMODE ) );
  66. }
  67.