home *** CD-ROM | disk | FTP | other *** search
/ Game Developers Magazine 4 / GDM004.ZIP / SOURCE / PLASPAL / PLASPAL.C next >
C/C++ Source or Header  |  1994-06-06  |  2KB  |  84 lines

  1. /*
  2.  
  3.    PLASPAL.C - Written by Phil Inch for Game Developers Magazine (Issue 4)
  4.    Contributed to the public domain.
  5.  
  6.    This program written and compiled with Borland C++ v3.1
  7.    Compatibility with other compilers is not guaranteed.
  8.  
  9.    Usage of this program is subject to the disclaimer printed
  10.    in the magazine.  You assume all risks associated with the use
  11.    of this program.
  12.  
  13. */
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <conio.h>
  18. #include <stdlib.h>
  19. #include <dos.h>
  20. #include <time.h>
  21. #include "vga.h"
  22.  
  23. #define MAX_PALETTE 192
  24. #define MAX_X 319
  25. #define MAX_Y 199
  26.  
  27. unsigned char palette[MAX_PALETTE][3];
  28.  
  29. void set_palette(void) {
  30.     unsigned char c;
  31.  
  32.   for ( c = 0; c < 64; c++ ) {
  33.     palette[c][0] = c;
  34.     palette[c][1] = 63-c;
  35.     palette[c][2] = 0;
  36.  
  37.     palette[c+64][0] = 63-c;
  38.     palette[c+64][1] = 0;
  39.     palette[c+64][2] = c;
  40.  
  41.     palette[c+128][0] = 0;
  42.     palette[c+128][1] = c;
  43.     palette[c+128][2] = 63-c;
  44.     }
  45.   SetBlock( 1, &palette[0][0], MAX_PALETTE );
  46. }
  47.  
  48. void draw_lines(void) {
  49.   int c;
  50.  
  51.   for (c=1; c<=192; c++)
  52.     VLine(c,0,199,c);
  53. }
  54.  
  55. void main(int argc, char **argv) {
  56.   int c;
  57.   char c1, c2, c3, c4;
  58.  
  59.     SetGraphicsMode();
  60.   set_palette();
  61.   draw_lines();
  62.  
  63.   if (*argv[1]=='C')
  64.     /* Cycle the palette until a key is pressed */
  65.     while ( !kbhit() ) {
  66.       c1 = palette[0][0];
  67.       c2 = palette[0][1];
  68.       c3 = palette[0][2];
  69.       for ( c = 0; c < MAX_PALETTE-1; c++ ) {
  70.               palette[c][0] = palette[c+1][0];
  71.               palette[c][1] = palette[c+1][1];
  72.               palette[c][2] = palette[c+1][2];
  73.         }
  74.       palette[MAX_PALETTE-1][0] = c1;
  75.       palette[MAX_PALETTE-1][1] = c2;
  76.       palette[MAX_PALETTE-1][2] = c3;
  77.         SetBlock( 1, &palette[0][0], MAX_PALETTE );
  78.       delay(10);
  79.       }
  80.   else getch();
  81.  
  82.   SetTextMode();
  83. }
  84.