Graph单元

时间:2023-12-20 09:03:20
感谢世外苏子恒同学提供
一、调用单元
例:uses graph;
二、初始化
例:initgraph(var graphdriver,graphmode:integer; const pathtodriver:string);
初始化图形包,draphdriver,draphmode为整形变量,pathtodriver为字符串变量;graphdriver为图形驱动器,graphmode为图形模式,pathtodriver是BGI文件夹路径
三、画直线I
例:line(x1,y1,x2,y2:integer);
二点确定一条直线
四、画直线II
例:lineto(x,y:integer);
从当前点向目标点(x,y)画直线
五、画圆
例:circle(x,y:integer;radius:word);
画一个以(x,y)为圆心,radius为半径的圆
六、画圆弧
例:arc(x,y:integer;stangle,endangel,radius:word);
画一个以(x,y)为中心,radius为半径,stangle和endangle为始角和终角的圆弧,角度沿逆时针方向,单位是度,0度指向东
七、画椭圆(弧)
例:ellipse(x,y:integer;stangle,endangel,xradius,yradius:word);
画一个以(x,y)为中心,xradius和yradius为半径,stangle和endangle为始角和终角的椭圆弧,角度沿逆时针方向,单位是度,0度指向东
八、设置颜色
例:setcolor(color:word);
设置线的颜色,也可以写成setcolor(red);
九、退出
例:closegraph;
退出图形模式
样例程序:
uses graph,crt;
var
 gm,gd,x,y,sx,sy,r,i:integer;
begin
  cursoroff;
  randomize;
  initgraph(gm,gd, ' '); //初始化图形界面
  r:=50;           //设置圆的半径
  x:=50;          //设置圆的初始坐标
  y:=50;
  sx:=10;        //设置圆每次移动的距离,相当于速度
  sy:=10;
  for i:=1 to 50 do begin
    circle(x,y,r); //在图形界面上画圆
    writeln('x:':5,x:5,'y:':5,y:5,'r:':5,r:5); //在文本界面上输出圆圈的坐标及半径
    delay(50);
    cleardevice;   //cleardevice:相当于图形界面的clrscr
    x:=x+sx;
    y:=y+sy;       //屏幕分辨率:1024*768
    if (x>=1024-r) or (x<=r) then sx:=-sx;
    if (y>=768-r) or (y<=r) then sy:=-sy;
  end;
  closegraph;     //关闭图形界面
end.