Cong Bac 3
Vi du 2 :
Program Cong_bac_3;
USES graph,crt;
VAR
pi:array[0..3] of real;
u: real;
xi,yi:array[0..3,0..3]of real;
x,y:array[0..3]of real;
m,n:array[0..100]of real;
xdau,Gd,Gm,t,i,j,k,l:integer;
a1,b1,c,s:real;
f:text;
(*************************************************)
{-------------Ve he truc toa do------------}
procedure khoitao;
begin
Gd := Detect;
InitGraph(Gd, Gm, 'c:\tp\bgi ');
if GraphResult <> grOk then Halt(1);
directvideo:=False;
setbkcolor(1);
setcolor(14);
setviewport(getmaxX div 2,getmaxY div 2,getmaxX,getmaxY,false);
line(-320,0,319,0);
line(319,0,310,-5);
line(319,0,310,5);
line(0,239,0,-240);
line(-5,-230,0,-240);
line(5,-230,0,-240);
outtextxy(-10,-10,'O');
outtextxy(305,10,'x');
outtextxy(10,-230,'y');
end;
(*************************************************)
{thu tuc ve duong cong tron theo thuat toan CASTELJAU}
PROCEDURE ve;
Var
i,j : integer;
BEGIN
moveto(round(x[0]),round(y[0]));
for i:=0 to 3 do
Begin
yi[i,0]:=y[i];
xi[i,0]:=x[i];
End;
u:=0;
while u<=1 do
Begin
for j:=1 to 3 do
Begin
for i:=j to 3 do
Begin
xi[i,j]:=(1-u)*xi[i-1,j-1]+u*xi[i,j-1];
yi[i,j]:=(1-u)*yi[i-1,j-1]+u*yi[i,j-1];
End;
End;
{lineto(round(xi[i,j]),round(yi[i,j]));}
putpixel(round(xi[i,j]),round(yi[i,j]),WHITE);
delay(0);
u:=u+0.0001
End; END;
(*************************************************)
{-------------Chuong Trinh Chinh------------}
BEGIN
l:=6; {l phai la so chan}
m[0]:=-90; n[0]:=100;
m[1]:=-60; n[1]:=60;
m[2]:=-40; n[2]:=80;
m[3]:=0; n[3]:=10;
m[4]:=60; n[4]:=140;
m[5]:=160; n[5]:=120;
m[6]:=260; n[6]:=220;
khoitao;
i:=0;
x[0]:=m[i];
y[0]:=n[i];
i:=i+1;
x[2]:=m[i];
y[2]:=n[i];
circle(round(x[2]),round(y[2]),2);
x[1]:=x[2]-5;
y[1]:=y[2]-5;
i:=i+1;
x[3]:=m[i];
y[3]:=n[i];
x[2]:=(8*x[2]-x[0]-3*x[1]-x[3])/3;
y[2]:=(8*y[2]-y[0]-3*y[1]-y[3])/3;
circle(round(x[0]),round(y[0]),2);
circle(round(x[3]),round(y[3]),2);
ve;
while i<l do
Begin
x[0]:=x[3];y[0]:=y[3];
x[1]:=x[3]+(x[3]-x[2]);
y[1]:=y[3]+(y[3]-y[2]);
i:=i+1;
x[2]:=m[i];
y[2]:=n[i];
circle(round(x[2]),round(y[2]),2);
i:=i+1;
x[3]:=m[i];
y[3]:=n[i];
x[2]:=(8*x[2]-x[0]-3*x[1]-x[3])/3;
y[2]:=(8*y[2]-y[0]-3*y[1]-y[3])/3;
circle(round(x[0]),round(y[0]),2);
circle(round(x[3]),round(y[3]),2);
ve;
End;
repeat until
keypressed;
closegraph;
END.
Bạn đang đọc truyện trên: Truyen2U.Pro