
Graphics Statements
Learning graphics, is very simple - all you have to learn is how to initialise graphics and then use your graphics knowledge to display whatever you want! Now, the following statements are found in the graph unit which are used to output graphically. Then I will show you an example program using the graph unit, to demonstrate how the statments below work:
|
Statement Description Example |
SetBkColor(colour/colour code); This will set the background colour of the screen to the colour indicated within the parenthesis. SetBkColor(Brown); or |
SetBkColor(6); |
SetColor(colour/colour code); This will set the text colour to the colour indicated within the parenthesis. SetColor(Green); or |
SetColor(2); |
OutText(''); This statement will output the text indicated within the inverted commas. OutText('BGI Graphics'); |
OutTextXY(X,Y,''); This is very similar to the one before this statement, except in that it move the cursor position indicated as shown OutTextXY(300,100,'BGI Graphics'); |
MoveTo(X,Y); Takes the cursor position to that indicated in the brackets. MoveTo(GetMaxX,GetMaxY); |
PutPixel(X,Y,colour/colour code); Places a small pixel at X pixels left and Y pixels down. PutPixel(50,128,Cyan); or |
PutPixel(50,128,5); |
Line(X,Y); Draws a line from the position of the cursor to X, Y. Line(30,111); |
LineTo(X1,Y1,X2,Y2); Draws a line from X1, Y1 to X2, Y2. LineTo(0,0, GetMaxX,GetMaxY); |
Rectangle(X1,Y1,X2,Y2); Draws a rectangle from point X1, Y1 to point X2, Y2. Rectangle(30,50,25,45); |
Circle(X,Y,Radius); Draws a circle from point X, Y with a radius length of Radius. Circle(GetMaxX Div 2, GetMaxY Div 2, 100); |
Ellipse(X,Y,P,Q,HorR,VerR); Draws an ellipse with centre point X,Y starting from P degrees to Q degrees, with a horizontal radius of HorR and a vertical radius of VerR. Ellipse(300,160, 0,360,60,40); |
Arc(X,Y,P,Q,Radius); Draws an arc starting from X,Y starting with an angle of Pdegrees and ending with an angle of Q degrees, with radius Radius. Arc(100,200,0,90,70); |
PieSlice(X,Y,P,Q,Radius); Similar to the arc();, except in that it is a pie. PieSlice(90,150,20,95,100); |
Bar(X1,Y1,X2,Y2); Draws a bar filled with the current colour, starting from X1, X2 to Y1, Y2. Bar(50,100,150,500); |
Bar3D(X1,Y1,X2,Y2, Depth,ThreeD_Top); Similar to the one above, except in that it is 3D. The last parameter indicates the 3D top of the 3D Bar. Bar3D(120,100,250, 150,50,TopOn); |
|
Below is a really fantastic graphics program, which uses most of the graphics statements above. If you could not run the program because of a graphics error, then send me an e-mail and I will help you how to do so. But first of all, try the path of the BGI file as shown above. You can download or copy this program:
Program Lesson8_Program2;
{Author: Victor J. Saliba}
{victorsaliba@hotmail.com}
{Website: http://pascal-programming.info/}
Uses Crt,Graph;
Var Gd, Gm,
Radius, Grow, IncP, IncQ : Integer;
DecrP, DecrQ : Boolean;
Begin
Gd := Detect;
InitGraph(Gd, Gm, '');
{Do not forget to change the dir path}
{Try C:\TP\BGI}
if GraphResult <> grOk then
Halt(1);
Randomize;
SetColor(Random(15)+1);
{In the following loop, 600 circles:
circles with different radii are
drawn. Everytime the loop is repeated,
the radius increases by
one, and thus the circle becomes +1
larger than the previous one.}
For Radius := 1 to 600 do
Begin
Circle(GetMaxX Div 2, GetMaxY Div 2, Radius);
Delay(1);
End;
ClearViewPort;
SetTextJustify(230, GetMaxY Div 2);
OutTextXY(230,GetMaxY Div 2,'Prepare for another one...');
Delay(1000);
ClearViewPort;
Grow := 0;
{The ellipse loop, is similar to the one
above except in that the vertical
radius increases by 1}
For Radius := 1 to 600 do
Begin