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;
{---------Thuat toan ve tam giac--}
procedure vetamgiac(x1,y1,x2,y2,x3,y3,m:integer);
Begin
outtextxy(x1,y1,'A');
outtextxy(x2,y2,'B');
outtextxy(x3,y3,'C');
setcolor(m);
line(x1,y1,x2,y2);
line(x1,y1,x3,y3);
line(x2,y2,x3,y3);
End;
{----------nhap toa do 1 diem----}
procedure NhapDiem(var x,y:integer;ten:char);
Begin
Writeln('Nhap toa do cho diem ',ten);
write(ten,'(x,y)=');readln(x,y);
End;
{---------to mau tam giac-----------}
procedure tomau(mv,mt,yb,yt:integer);
var i,j,k,l,r:integer;
Begin
for i:=yb+1 to yt-1 do
for j:=0 to getmaxx do
if getpixel(j,i)=mv then
begin
l:=j;
for k:=j+1 to getmaxx do
if getpixel(k,i)=mv then
begin
r:=k;
break;
end;
for k:=l+1 to r-1 do putpixel(k,i,mt);
end;
End;
{---------tim max va min----------}
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;
{---------------CHUONG TRINH CHINH---------------------}
BEGIN
clrscr;
Nhapdiem(xa,ya,'A');
Nhapdiem(xb,yb,'B');
Nhapdiem(xc,yc,'C');
maunen:=3;
mauvien:=6;
mauto:=14;
maxmin(ya,yb,yc,ytop,ybottom);
khoitao;
setbkcolor(maunen);
vetamgiac(xa,ya,xb,yb,xc,yc,mauvien);
tomau(mauvien,mauto,ybottom,ytop);
dunghinh;
ketthuc;
END.