home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PASTUT34
/
GRAPHICS.TXT
< prev
next >
Wrap
Text File
|
1993-06-12
|
3KB
|
80 lines
GRAPHICS.
▀▀▀▀▀▀▀▀▀
More than 70 graphics functions and procedures are provided with Turbo
Pascal version 6.0 and together with 20 Crt functions and procedures
provide an excellent environment for screen graphics.
A typical graphics command is LINE(x1,y1,x2,y2: integer);
The syntax in version 3 was different and the definition of a graphics
screen was also different, so care must be taken if converting between
versions. Borland provide a 'Unit' called Graph3 which can be used in
place of the new unit called Graph so that version 3 graphics can still
be used.
With version 6.0, the first requirement is to make the units Crt and
Graph available to the user program by the declaration:
USES Crt,Graph;
The following six statements (or similar) should then be included in the
program, after the appropriate declaration of the variables:
var
GraphDriver,GraphMode,Detect : integer;
MaxX,MaxY : integer;
....
....
Begin
Detect:=0;
GraphDriver:=Detect;
InitGraph(GraphDriver,GraphMode,'');
MaxX:=GetMaxX;
MaxY:=GetMaxY;
SetViewPort(0,0,MaxX,MaxY,ClipOff);
....
The first three commands initialize the graphics to suit the present
hardware, but it is essential that the appropriate *.BGI file is
available on the default drive. i.e. the file CGA.BGI should be
available for a CGA monitor (320 x 200) or EGAVGA.BGI for a VGA display
(640 x 480 pixels). The last three commands determine the size of the
screen in pixels and in this case set the whole screen for graphics output.
The background and foreground colours should be set by use of the commands:
SetBkColor(ColorNum:word); {Note the American spelling of Color}
SetColor(ColorNum:word);
The various colours have predefined constant values.
Black =0;
Blue =1;
......
Red =4;
......
White =15;
The program GRAPHICS.PAS illustrates the graphics procedures by drawing
a parabola on the screen as a series of very small straight lines. This
program is incomplete in order that the user can add the necessary
statements to show markers on the axes, with appropriate values.
Although this is only a very simple program, it would have been wise to
place all the graphics initialization statements into a procedure, to
allow greater flexibility and extension. (But note that the procedure
InitGraph exists and has already been called above, so avoid a second
use of this name).
To appreciate the many graphics procedures provided by Turbo Pascal,
users should run the program BGIDEMO.EXE which is available on the
diskettes supplied by Borland.
GRAPHICS.TXT
Revised 22.1.93