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

  1. /* HORIZON.C: VGA graphics with cycling of 256 colors */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <graph.h>
  7.  
  8. #define RED 0x0000003FL
  9. #define GRN 0x00003F00L
  10. #define BLU 0x003F0000L
  11. #define WHT 0x003F3F3FL
  12. #define STEP 21
  13.  
  14. struct videoconfig screen;
  15. long int rainbow[512];
  16.  
  17. main()
  18. {
  19.    int i;
  20.    long int col, gray;
  21.  
  22.    if( _setvideomode( _MRES256COLOR ) == 0 )
  23.    {
  24.       printf("This program requires a VGA card.\n" );
  25.       exit( 0 );
  26.    }
  27.    for( col = 0; col < 64; col++ )
  28.    {
  29.       gray = col | (col << 8) | (col << 16);
  30.       rainbow[col] = rainbow[col + 256] = BLU & gray;
  31.       rainbow[col + 64] = rainbow[col + 64 + 256] = BLU | gray;
  32.       rainbow[col + 128] = rainbow[col + 128 + 256] = RED | (WHT & ~gray);
  33.       rainbow[col + 192] = rainbow[col + 192 + 256] = RED & ~gray;
  34.    }
  35.    _setvieworg( 160, 85 );
  36.  
  37.    for( i = 0; i < 255; i++ )
  38.    {
  39.       _setcolor( 255 - i );
  40.       _moveto( i, i - 255 );
  41.       _lineto( -i, 255 - i );
  42.       _moveto( -i, i - 255 );
  43.       _lineto( i, 255 - i );
  44.       _ellipse( _GBORDER, -i, -i / 2, i, i / 2 );
  45.    }
  46.    for( i = 0; !kbhit(); i += STEP, i %= 256 )
  47.       _remapallpalette( &(rainbow[i]) );
  48.  
  49.    _setvideomode( _DEFAULTMODE );
  50. }
  51.