home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc / qc25 / horizon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  1.2 KB  |  50 lines

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