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

  1. Program ThirdBgiDemo;
  2. {--------------------------------------------------------------------}
  3. { This is a sample program to introduce the user to a graphics       }
  4. { program using the Borland Graphics Interface.  It also introduces  }
  5. { concepts of writing device independant code.                       }
  6. {                                                                    }
  7. { This program will first place a border around the edge of the      }
  8. { screen, and then proceed to use the SetAspectRatio procedure to    }
  9. { change the way a circle will appear on the screen.  Note the use   }
  10. { of the "Detect Feature" when initiating the graphics mode.         }
  11. {--------------------------------------------------------------------}
  12.  
  13. Uses Crt, Graph;          { Link in the standard units Crt and Graph }
  14.  
  15. Const
  16.   BorderColor : Byte = LightGreen;
  17.                           { Color of the border that is drawn        }
  18.   DrawingColor : Byte = Yellow;
  19.                           { Main drawing color for images            }
  20.   AltDrawingColor : Byte = LightCyan;
  21.                           { Secondary drawing color                  }
  22.   EscString = 'Press any key to Exit';
  23.                           { Message to be output when drawing image  }
  24.   Radius = 60;            { Default value for circle's radius        }
  25.   AspectFactor = 2000;    { Multiplication factor for Aspect Ratio   }
  26.   PathForDrivers = '';    { Location of the BGI's support files      }
  27.  
  28. Var
  29.   GraphDriver,
  30.   GraphMode    : Integer;  { Variables to be passed to InitGraph      }
  31.   Ch           : Char;     { Temporary variable used to pause program }
  32.   GrErrorCode  : Integer;  { Used to store result of InitGraph call   }
  33.   CenterX,
  34.   CenterY      : Integer;  { Value to store Center position of Screen }
  35.   Counter      : Integer;  { Loop control variable                    }
  36.   MaxX,
  37.   MaxY,                    { Storage for Maximum X and Maximum Y      }
  38.   XAsp,
  39.   YAsp         : Word;     { Storage for current Aspect Ratios        }
  40.   CGAColorSet,
  41.   MonoColorSet : Boolean;  { Boolean to determine color choices       }
  42.  
  43. Procedure CreateColors( Mono : Boolean; CGASet : Boolean );
  44. {---------------------------------------------------------------------}
  45. { This procedure will reset the constants defined above for border    }
  46. { color, drawing color, and alternate drawing color, if a mono card,  }
  47. { a CGA card, or an MCGA card is detected at run time.                }
  48. {---------------------------------------------------------------------}
  49. Var
  50.   MonoColorChoice : Word;  { We will assign the result of the         }
  51.                            { GetMaxColor procedure to this variable   }
  52.                            { when an HGC is detected.                 }
  53.  
  54. Begin
  55.   If( Mono ) Then
  56.   Begin
  57.     MonoColorChoice := GetMaxColor;
  58.     BorderColor := MonoColorChoice;
  59.     DrawingColor := MonoColorChoice;
  60.     AltDrawingColor := MonoColorChoice;
  61.   End;
  62.   If( CGASet ) Then
  63.   Begin
  64.     SetGraphMode( 1 );     { Select a CGA mode that allows Multiple   }
  65.                            { Colors on the screen                     }
  66.     BorderColor := 1;      { Select first Palette entry               }
  67.     DrawingColor := 2;     { Select second Palette entry              }
  68.     AltDrawingColor := 3;  { Select third Palette entry               }
  69.   End;
  70. End;
  71.  
  72.  
  73. Begin
  74.   GraphDriver := Detect;  { Request BGI to use detect feature         }
  75.   InitGraph( GraphDriver, GraphMode, PathForDrivers );
  76.                           { Initialize the requested graphics mode    }
  77.   GrErrorCode := GraphResult; { Check to see if an error occurred     }
  78.   If( GrErrorCode <> grOK ) Then { If So, Act upon the error          }
  79.   Begin
  80.     Write( 'A graphics error has occurred: ' );
  81.     Writeln( GraphErrorMsg( GrErrorCode ) );
  82.     Writeln( 'Program Halted!' );
  83.     Halt( 1 );
  84.   End;
  85.   MonoColorSet := False;  { Initialize variables before use           }
  86.   CGAColorSet := False;   {      "         "        "    "            }
  87.   Case GraphDriver Of     { Take an action on the detected driver     }
  88.     1..2 : CGAColorSet := True;
  89.     4    : SetGraphMode( 0 );{ Set the 64K EGA card into multi colors }
  90.     5    : MonoColorSet := True;
  91.     7    : MonoColorSet := True;
  92.     8    : CGAColorSet := True;
  93.     10   : MonoColorSet := True;
  94.   End;
  95.   CreateColors( MonoColorSet, CGAColorSet );
  96.   MaxX := GetMaxX;        { Determine the maximum X coordinate       }
  97.   MaxY := GetMaxY;        { Determine the maximum Y coordinate       }
  98.   SetColor( BorderColor );{ Select the border color to be used       }
  99.   Rectangle( 0,0,MaxX,MaxY );{ Draw the border                       }
  100.   Counter := TextHeight( EscString ) + 2;
  101.                           { Determine the height of the string to be }
  102.                           { outputted and adjust line accordingly    }
  103.   Line( 0,MaxY - Counter, MaxX, MaxY - Counter );
  104.   SetTextJustify( LeftText, BottomText );
  105.                           { Reset the text justification to simplify }
  106.   Counter := TextWidth( EscString );
  107.                           { Determine length of text to help in      }
  108.                           { centering it                             }
  109.   OutTextXY( ( ( MaxX Div 2 ) - ( Counter Div 2 ) ), MaxY, EscString );
  110.   SetColor( DrawingColor );{ Select the main drawing color           }
  111.   CenterX := MaxX Div 2;  { Compute the coordinates of the center of }
  112.   CenterY := MaxY Div 2;  { the graphics screen                      }
  113.   GetAspectRatio( XAsp, YAsp );
  114.   Repeat
  115.     For Counter := 1 to 5 Do
  116.     Begin                 { Through each loop reset X Aspect ratio   }
  117.       SetAspectRatio( Counter * AspectFactor, YAsp );
  118.       Circle( CenterX, CenterY, Radius );
  119.       SetColor( Black );
  120.       Circle( CenterX, CenterY, Radius );
  121.       If( Odd( Counter ) ) Then
  122.         SetColor( DrawingColor )
  123.       Else
  124.         SetColor( AltDrawingColor );
  125.     End;
  126.   Until KeyPressed;       { Conitnue looping until a key is pressed  }
  127.   Ch := Readkey;          { Remove the pressed key from the buffer   }
  128.   CloseGraph;             { Shut down the graphics system            }
  129. End.
  130.