home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / graphics / animate.c next >
Encoding:
C/C++ Source or Header  |  1988-10-26  |  1.7 KB  |  49 lines

  1. /* ANIMATE.C illustrates animation functions including:
  2.  *          _imagesize     _getimage     _putimage
  3.  */
  4.  
  5. #include <conio.h>
  6. #include <stddef.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <graph.h>
  10.  
  11. short action[5]  = { _GPSET,   _GPRESET, _GXOR,    _GOR,     _GAND    };
  12. char *descrip[5] = { "PSET  ", "PRESET", "XOR   ", "OR    ", "AND   " };
  13.  
  14. main()
  15. {
  16.     char far *buffer;
  17.     short i, x, y = 30;
  18.     size_t imsize;
  19.     short mode = _VRES16COLOR;
  20.  
  21.     while( !_setvideomode( mode ) )         /* Find best graphics mode    */
  22.         mode--;
  23.     if (mode == _TEXTMONO )
  24.         exit( 1 );                          /* No graphics available      */
  25.     _setcolor( 3 );
  26.     for ( i = 0; i < 5; i++ )
  27.     {
  28.         x = 50; y += 40;
  29.         _settextposition( 1, 1 );           /* Display action type        */
  30.         _outtext( descrip[i] );
  31.                                             /* Draw and measure ellipse   */
  32.         _ellipse( _GFILLINTERIOR, x - 15, y - 15, x + 15, y + 15 );
  33.         imsize = (size_t)_imagesize( x - 16, y - 16, x + 16, y + 16 );
  34.         buffer = (char far *)_fmalloc( imsize );
  35.         if ( buffer == (char far *)NULL )
  36.             exit( 1 );
  37.                                             /* Get master copy of ellipse */
  38.         _getimage( x - 16, y - 16, x + 16, y + 16, buffer );
  39.         while( x < 260 )                    /* Copy row of ellipses       */
  40.         {                                   /*   with specified action    */
  41.             x += 5;
  42.             _putimage( x - 16, y - 16, buffer, action[i] );
  43.         }
  44.         _ffree( (char far *)buffer );       /* Free memory                */
  45.         getch();
  46.     }
  47.     exit( !_setvideomode( _DEFAULTMODE ) );
  48. }
  49.