TRANSFORMASI

uses graph,crt;
type tmatriks = array[1..3,1..3] of real;
tvektor  = array[1..3] of real;
ttitik   = array[1..4] of real;
var gd,gm,i,j,counter,n     : integer;
XVmin,XVmax,
YVmin,YVmax,
XWmin,XWmax,
YWmin,YWmax : integer;
ms          : tmatriks;
vek,vekhasil         : tvektor;
Xw,Yw,Xv,Yv : ttitik;

procedure BuatKotak(x1,y1,x2,y2 : integer; warnakotak,warnabatas : word);
begin
setcolor(warnabatas);   {menentukan warna batas }
rectangle(x1,y1,x2,y2);   { membuat kotak }
setfillstyle(solidfill,warnakotak);   { menentukan warna kotak }
floodfill((x1+x2) div 2,(y1+y2) div 2,warnabatas);   { proses pewarnaan kotak }
end;

procedure gambarPoligon(segiX : integer);
begin
end;

begin { program utama }
{inisialisasi grafik }
gd := detect;
initgraph(gd,gm,’c:\tpascal7\bgi’);

BuatKotak(1,1,479,479,blue,cyan);   { window tempat penggambaran obyek transformasi }
BuatKotak(482,1,639,479,green,lightcyan);   { window tempat modifikasi matriks transformasi }

{ membuat sumbu x dan y }
for i := 5 to 475 do begin
putpixel((1+479) div 2,i,lightgray);
putpixel(i,(1+479) div 2,lightgray);
end;

{ matriks transformasi }
Ms[1,1] := -1;Ms[1,2] := 0;Ms[1,3] := 0;
Ms[2,1] := 1.5;Ms[2,2] := 1;Ms[2,3] := 0;
Ms[3,1] := 3;Ms[3,2] := 1;Ms[3,3] := 1;

{ titik-titik poligon }
Xw[1] := 1;Xw[2] := 3;Xw[3] := 3;Xw[4] := 1;
Yw[1] := 1;Yw[2] := 1;Yw[3] := 3;Yw[4] := 3;

{ transformasi window ke viewport }
XVmin := 1;XVmax := 479;   { titik-titik batas viewport }
YVmin := 1;YVmax := 479;

XWmin := -10;XWmax := 10;  { titik-titik batas window }
YWmin := -10;YWmax := 10;
{ rumus mwnentukan letak titik-titik x dan y di viewport }
for i := 1 to 4 do begin
Xv[i] := XVmin + (Xw[i]-XWmin)/(XWmax-XWmin)*(XVmax-XVmin);
Yv[i] := YVmax – (Yw[i]-YWmin)/(YWmax-YWmin)*(YVmax-YVmin);
end;
{ menggambar poligon }
line(round(Xv[1]),round(Yv[1]),round(Xv[2]),round(Yv[2]));
line(round(Xv[2]),round(Yv[2]),round(Xv[3]),round(Yv[3]));
line(round(Xv[3]),round(Yv[3]),round(Xv[4]),round(Yv[4]));
line(round(Xv[4]),round(Yv[4]),round(Xv[1]),round(Yv[1]));
{ perkalian matriks untuk transformasi poligon }
for n := 1 to 4 do begin
for i := 1 to 3 do begin
vekhasil[i] := 0;
counter := 1;
for j := 1 to 3 do begin
if counter = 1 then vek[j] := Xw[n] else
if counter = 2 then vek[j] := Yw[n] else
If counter = 3 then vek[j] := 1;
vekhasil[i] := vekhasil[i] + vek[j] * Ms[j,i];
inc(counter);
end;
end;
Xw[n] := vekhasil[1];
Yw[n] := vekhasil[2];
end;
{idem sebaiknya dibuat prosedur }
for i := 1 to 4 do begin
Xv[i] := XVmin + (Xw[i]-XWmin)/(XWmax-XWmin)*(XVmax-XVmin);
Yv[i] := YVmax – (Yw[i]-YWmin)/(YWmax-YWmin)*(YVmax-YVmin);
end;
{ menggambar poligon }
setcolor(yellow);
line(round(Xv[1]),round(Yv[1]),round(Xv[2]),round(Yv[2]));
line(round(Xv[2]),round(Yv[2]),round(Xv[3]),round(Yv[3]));
line(round(Xv[3]),round(Yv[3]),round(Xv[4]),round(Yv[4]));
line(round(Xv[4]),round(Yv[4]),round(Xv[1]),round(Yv[1]));

readln;
closegraph;
end.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: