Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - I want to draw with Pascal. What should I do?
I want to draw with Pascal. What should I do?
In the BGI drawing of TP7, there are basically two external files:

Egavga.bgi

Graph.tpu

It is best to copy these two files to the current directory (the current directory refers to the directory you see with the main menu file-Change dir ...), which can ensure that the graphics system can be started without errors.

At the same time, it is best to use it with CRT unit, which has many useful functions. Because many CRT units are not patched, there will always be errors when running under windows, so I won't introduce them.

The basic form is as follows:

Program Myprog

Use charts;

defined variable

Gd, gm, ecode: integer;

begin

GD:= Detect;

InitGraph(gd,gm,' '); {Start the drawing system}

ecode:= graph result;

If ecode & lt& gt, drink it.

begin

Writeln('Graphics error:',GraphErrorMsg(ecode));

Quit;

End;

{Drawing function and calculation part}

readln

Closegraph{ Close the drawing system}

End.

InitGraph(gd,gm,' '); When starting the drawing system, if there are errors, there are reasons for editing and typing errors. For example, the file Egavga.bgi cannot be found in the current directory.

Of course, you can also specify its path, such as: InitGraph(gd, gm,' d: \ tp7 \ bgi'); If the specified drawing mode is Detect (automatic detection, generally return to 640*480* 16 color mode).

Finally, readln is also important. Otherwise, when the graphics flash, the program is over and you can't see clearly.

There are many drawing functions, I can only introduce a few, and you can see the online help of TP7 for the rest.

Clear Device Clear Screen

PutPixel(X, y: integer; Pixel: word); Draw a point. X, y are coordinates, piexl is color, and all colors can use plastic code 0- 15.

Line(x 1, y 1, x2, y2: integer); Draw a straight line from (x 1, y 1) to (x2, y2).

Circle (x, y: integer; Radius: word); Draw a circle with the center (x, y) and radius.

Ellipse (x, y: integer; StAngle,EndAngle:Word; XRadius,YRadius:Word);

Draw an ellipse, the center of the circle (x, y), the starting angle StAngle, the ending angle EndAngle, the major and minor axis radii XRadius, YRadius.

Sector (x, y: integer; StAngle,EndAngle,XRadius,YRadius:Word); Sector ellipse

SetFillStyle (mode: Word color: word); Set the fill mode and fill color.

setline style(line style:Word; Pattern: characters; Thickness: word); Set the appearance and thickness of the line type.

OutTextXY(X, y: integer; TextString: string); Output text at (x, y). (Don't use write when drawing)

Set the background color and foreground color.

RestoreCrtMode switches to our usual text mode.

SetGraphMode(GetGraphMode); Switch to drawing mode, which cannot be used after closegraph closes the drawing.

There's no way to call again. Ask for help yourself. Here is a simple example:

Program Myprog

Use charts;

defined variable

Gd, gm, ecode: integer;

begin

GD:= Detect;

InitGraph(gd,gm,' ');

ecode:= graph result;

If ecode & lt& gt, drink it.

begin

Writeln('Graphics error:',GraphErrorMsg(ecode));

Quit;

End;

set color(3);

Outtextxy (10,450,' Press Enter ...');

set color(6);

SetLineStyle(0,0, 1); Circle (320,240,100); readln

Line (0,0,639,479); readln

SetFillStyle( 1, 1);

Plate (300, 200, 0, 90, 90, 80);

readln

closegraph

End.