home *** CD-ROM | disk | FTP | other *** search
- Program ThirdBgiDemo;
- {--------------------------------------------------------------------}
- { This is a sample program to introduce the user to a graphics }
- { program using the Borland Graphics Interface. It also introduces }
- { concepts of writing device independant code. }
- { }
- { This program will first place a border around the edge of the }
- { screen, and then proceed to use the SetAspectRatio procedure to }
- { change the way a circle will appear on the screen. Note the use }
- { of the "Detect Feature" when initiating the graphics mode. }
- {--------------------------------------------------------------------}
-
- Uses Crt, Graph; { Link in the standard units Crt and Graph }
-
- Const
- BorderColor : Byte = LightGreen;
- { Color of the border that is drawn }
- DrawingColor : Byte = Yellow;
- { Main drawing color for images }
- AltDrawingColor : Byte = LightCyan;
- { Secondary drawing color }
- EscString = 'Press any key to Exit';
- { Message to be output when drawing image }
- Radius = 60; { Default value for circle's radius }
- AspectFactor = 2000; { Multiplication factor for Aspect Ratio }
- PathForDrivers = ''; { Location of the BGI's support files }
-
- Var
- GraphDriver,
- GraphMode : Integer; { Variables to be passed to InitGraph }
- Ch : Char; { Temporary variable used to pause program }
- GrErrorCode : Integer; { Used to store result of InitGraph call }
- CenterX,
- CenterY : Integer; { Value to store Center position of Screen }
- Counter : Integer; { Loop control variable }
- MaxX,
- MaxY, { Storage for Maximum X and Maximum Y }
- XAsp,
- YAsp : Word; { Storage for current Aspect Ratios }
- CGAColorSet,
- MonoColorSet : Boolean; { Boolean to determine color choices }
-
- Procedure CreateColors( Mono : Boolean; CGASet : Boolean );
- {---------------------------------------------------------------------}
- { This procedure will reset the constants defined above for border }
- { color, drawing color, and alternate drawing color, if a mono card, }
- { a CGA card, or an MCGA card is detected at run time. }
- {---------------------------------------------------------------------}
- Var
- MonoColorChoice : Word; { We will assign the result of the }
- { GetMaxColor procedure to this variable }
- { when an HGC is detected. }
-
- Begin
- If( Mono ) Then
- Begin
- MonoColorChoice := GetMaxColor;
- BorderColor := MonoColorChoice;
- DrawingColor := MonoColorChoice;
- AltDrawingColor := MonoColorChoice;
- End;
- If( CGASet ) Then
- Begin
- SetGraphMode( 1 ); { Select a CGA mode that allows Multiple }
- { Colors on the screen }
- BorderColor := 1; { Select first Palette entry }
- DrawingColor := 2; { Select second Palette entry }
- AltDrawingColor := 3; { Select third Palette entry }
- End;
- End;
-
-
- Begin
- GraphDriver := Detect; { Request BGI to use detect feature }
- InitGraph( GraphDriver, GraphMode, PathForDrivers );
- { Initialize the requested graphics mode }
- GrErrorCode := GraphResult; { Check to see if an error occurred }
- If( GrErrorCode <> grOK ) Then { If So, Act upon the error }
- Begin
- Write( 'A graphics error has occurred: ' );
- Writeln( GraphErrorMsg( GrErrorCode ) );
- Writeln( 'Program Halted!' );
- Halt( 1 );
- End;
- MonoColorSet := False; { Initialize variables before use }
- CGAColorSet := False; { " " " " }
- Case GraphDriver Of { Take an action on the detected driver }
- 1..2 : CGAColorSet := True;
- 4 : SetGraphMode( 0 );{ Set the 64K EGA card into multi colors }
- 5 : MonoColorSet := True;
- 7 : MonoColorSet := True;
- 8 : CGAColorSet := True;
- 10 : MonoColorSet := True;
- End;
- CreateColors( MonoColorSet, CGAColorSet );
- MaxX := GetMaxX; { Determine the maximum X coordinate }
- MaxY := GetMaxY; { Determine the maximum Y coordinate }
- SetColor( BorderColor );{ Select the border color to be used }
- Rectangle( 0,0,MaxX,MaxY );{ Draw the border }
- Counter := TextHeight( EscString ) + 2;
- { Determine the height of the string to be }
- { outputted and adjust line accordingly }
- Line( 0,MaxY - Counter, MaxX, MaxY - Counter );
- SetTextJustify( LeftText, BottomText );
- { Reset the text justification to simplify }
- Counter := TextWidth( EscString );
- { Determine length of text to help in }
- { centering it }
- OutTextXY( ( ( MaxX Div 2 ) - ( Counter Div 2 ) ), MaxY, EscString );
- SetColor( DrawingColor );{ Select the main drawing color }
- CenterX := MaxX Div 2; { Compute the coordinates of the center of }
- CenterY := MaxY Div 2; { the graphics screen }
- GetAspectRatio( XAsp, YAsp );
- Repeat
- For Counter := 1 to 5 Do
- Begin { Through each loop reset X Aspect ratio }
- SetAspectRatio( Counter * AspectFactor, YAsp );
- Circle( CenterX, CenterY, Radius );
- SetColor( Black );
- Circle( CenterX, CenterY, Radius );
- If( Odd( Counter ) ) Then
- SetColor( DrawingColor )
- Else
- SetColor( AltDrawingColor );
- End;
- Until KeyPressed; { Conitnue looping until a key is pressed }
- Ch := Readkey; { Remove the pressed key from the buffer }
- CloseGraph; { Shut down the graphics system }
- End.