duong cong Bezier bac 3
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,a,c,s:array[0..100]of real;
xdau,Gd,Gm,t,i,j,k,l:integer;
a1,b1:real;
f:text;
(*************************************************)
{-------------Ve he truc toa do------------}
procedure khoitao;
begin
Gd := Detect; InitGraph(Gd, Gm, ' ');
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]),LIGHTMAGENTA);
delay(0);
u:=u+0.001
End;
END;
(*************************************************)
{-------------Chuong Trinh Chinh------------}
BEGIN
l:=8;
m[0]:=-290;
n[0]:=-200;
m[1]:=-290;
n[1]:=-200;
m[2]:=-190;
n[2]:=-100;
m[3]:=-90;
n[3]:=100;
m[4]:=-60;
n[4]:=60;
m[5]:=-40;
n[5]:=80;
m[6]:=0;
n[6]:=10;
m[7]:=60;
n[7]:=140;
m[8]:=160;
n[8]:=120;
m[9]:=260;
n[9]:=220;
khoitao;
i:=1;
c[0]:=0;
while i<=l do
Begin x[0]:=m[i];y[0]:=n[i];
circle(round(m[i]),round(n[i]),2);
c[i]:=(n[i+1]-n[i])/(m[i+1]-m[i]);
a[i]:=(m[i+1]-m[i])/(m[i+1]-m[i-1]);
s[i]:=(1-a[i])*c[i-1]+a[i]*c[i];
i:=i+1;
x[3]:=m[i];y[3]:=n[i];
circle(round(m[i]),round(n[i]),2);
c[i]:=(n[i+1]-n[i])/(m[i+1]-m[i]);
a[i]:=(m[i+1]-m[i])/(m[i+1]-m[i-1]);
s[i]:=(1-a[i])*c[i-1]+a[i]*c[i];
x[1]:=m[i-1]+(m[i-1]-m[i-2])/3;
y[1]:=n[i-1]+(m[i-1]-m[i-2])*s[i-1]/3;
x[2]:=m[i]-(m[i]-m[i-1])/3;
y[2]:=n[i]-(m[i]-m[i-1])*s[i]/3;
ve;
End;
repeat until
keypressed;
closegraph;
END.
Bạn đang đọc truyện trên: TruyenTop.Vip