home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST1010.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  2.2 KB  |  54 lines

  1. Program RGBPaletteGrayScale;
  2. {--------------------------------------------------------------}
  3. { This program is a demonstration of using the SetRGBPalette   }
  4. { procedure.  It will reset the 16 palette entrys to point to  }
  5. { DACs 0 through 15.  These DACs will then be reprogrammed to  }
  6. { create 16 shades of gray.                                    }
  7. {--------------------------------------------------------------}
  8.  
  9. Uses Crt, Graph;         { Link in necessary library units     }
  10.  
  11. Const
  12.   PathToDrivers = '';    { Location of support file for BGI    }
  13.   CValueIncrement = 3;   { Increment for Red, Green, Blue gun  }
  14.  
  15. Var
  16.   GraphDriver,
  17.   GraphMode : Integer;   { Variables for graphics mode         }
  18.   Ch : Char;             { Character to use for pausing        }
  19.   P : PaletteType;       { Palette record for GetPallet proc   }
  20.   I : Word;              { Loop counter variable.              }
  21.   ColorValue : Word;     { Value used for Red, Green, Blue gun }
  22.   Y1, Y2,
  23.   YInc,
  24.   MaxX,
  25.   MaxY : Word;           { Values used for creating bars       }
  26.  
  27. Begin
  28.   GraphDriver := VGA;   { Initialize graphics driver for VGA   }
  29.   GraphMode := VGAHi;   { Initialize mode to VGAHi res mode    }
  30.   InitGraph( GraphDriver, GraphMode, PathToDrivers );
  31.   ColorValue := 0;      { Start with true black                }
  32.   For I := 0 to 15 Do   { Point each palette entry to DAC I    }
  33.     SetPalette( I,I );
  34.   For I := 0 to 15 Do   { Create the gray scales               }
  35.   Begin
  36.     SetRGBPalette( I,ColorValue,ColorValue,ColorValue );
  37.     Inc( ColorValue, CValueIncrement );
  38.   End;
  39.   MaxY := GetMaxY;      { Store Maximum X resolution           }
  40.   MaxX := GetMaxX;      { Store Maximum Y resolution           }
  41.   YInc := MaxY Div 16;  { Create YInc as 1/16 of Y resolution  }
  42.   Y1 := 0;
  43.   Y2 := YInc;           { Initialize values for BAR procedure  }
  44.   For I := 0 to 15 do   { Create 16 bars on screen with our    }
  45.   Begin                 { new shades of gray                   }
  46.     SetFillStyle( SolidFill, I );
  47.     Bar( 0,Y1,MaxX,Y2 );
  48.     Inc( Y1, YInc );
  49.     Inc( Y2, YInc );
  50.   End;
  51.   Ch := Readkey;        { Pause for screen viewing             }
  52.   CloseGraph;           { Shut down graphics system            }
  53. End.
  54.