uses crt,graph;
var xa,ya,xb,yb,xc,yc,maunen,mauvien,mauto,ytop,ybottom:integer;
{----------------------khoi tao do hoa---------------------------- }
procedure Khoitao;
var gd,gm:integer;
Begin
gd:=detect;
initgraph(gd,gm,'d:\tp\bgi');
if graphresult <> grok then
Begin
writeln('Loi khoi tao do hoa, kiem tra lai duong dan');
readln;
halt(1);
End;
End;
{------------Dung Hinh----------------}
procedure DungHinh;
Begin
repeat until keypressed;
End;
{---------ket thuc do hoa----}
procedure Ketthuc;
Begin
closegraph;
End;
{-----------nhap toa do 1 diem----}
procedure nhapdiem(var x,y:integer;ch:char);
begin
writeln('Nhap toa do cho diem ',ch);
write(ch,'(x,y)= ');readln(x,y);
end;
{----------ve tam giac----------}
procedure vetamgiac(x1,y1,x2,y2,x3,y3,mv:integer);
Begin
outtextxy(x1,y1,'A');
outtextxy(x2,y2,'B');
outtextxy(x3,y3,'C');
setcolor(mv);
line(x1,y1,x2,y2);
line(x1,y1,x3,y3);
line(x2,y2,x3,y3);
End;
{----------Tim max min 3 so------------}
procedure maxmin(a,b,c:integer; var max,min:integer);
Begin
{tim max}
max:=a;
if max<b then max:=b;
if max<c then max:=c;
{tim min}
min:=a;
if min>b then min:=b;
if min>c then min:=c;
End;
{-------to mau tam giac--------------------}
procedure tomautamgiac(mv,mt,ybt,yt:integer);
var i,k,xl,xr:integer;
Begin
for k:=ybt+1 to yt-1 do
begin
for i:=0 to getmaxx do
if getpixel(i,k)=mv then
begin
xl:=i;
for i:=xl+1 to getmaxx do
if getpixel(i,k)=mv then xr:=i;
end;
for i:=xl+1 to xr-1 do putpixel(i,k,mt);
end;
End;
{-----------CHUONG TRINH CHINH------------}
BEGIN
clrscr;
nhapdiem(xa,ya,'A');
nhapdiem(xb,yb,'B');
nhapdiem(xc,yc,'C');
maunen:=3;
mauvien:=6;
mauto:=14;
khoitao;
setbkcolor(maunen);
vetamgiac(xa,ya,xb,yb,xc,yc,mauvien);
maxmin(ya,yb,yc,ytop,ybottom);
tomautamgiac(mauvien,mauto,ybottom,ytop);
dunghinh;
ketthuc;
END.