Program berikut dibuat dengan menggunakan Free Pascal…
Isinya mengenai Pembentukan garis melalui dua buah titik yang dinniputkan oleh User..
didalamnya sudah berisi translasi, penskalaan dan rotasi…
Semoga program ini bermanfaat………..

uses graph,crt;
var x1,x2,y1,y2,xtrans,ytrans:integer;
step,k,skala,xpst,ypst:integer;
dx,dy:real;
xm,ym,x,y,derajat:real;
pilih:char;
procedure init;
var gd, gm : integer;
begin
gm:=detect; gd:=0;
InitGraph(gd,gm,’C:\TP\bgi’);
if GraphResult <> grOk then


begin
Writeln(‘Graph driver ‘,gd,’ graph mode ‘,gm,’ not supported’);
Halt(1);
end;
end;
procedure destroy;
begin
closegraph;
end;
procedure input;
begin
writeln(‘program pembangkitan garis DDA’);
writeln(‘=====================’);
writeln;
write(‘masukkan nilai x1:’);
readln(x1);
write(‘masukkan nilai y1:’);
readln(y1);
write(‘masukkan nilai x2:’);
readln(x2);
write(‘masukkan nilai y2:’);
readln(y2);
end;
procedure Garis_DDA(x1,y1,x2,y2:integer);
begin
dx:=x2-x1;
dy:=y2-y1;
x:=x1;
y:=y1;
if abs (dx) > abs(dy) then step:=round(abs(dx))
else
step:=round (abs(dy));
xm:=dx/step;
ym:=dy/step;
putpixel(round(x),round(y),50);
for k:=1 to step do
begin
x:=x+xm;
y:=y+ym;
putpixel (round(x),round(y),50);
end;
end;
procedure transLine(xstart,ystart,xend,yend,xtrans,ytrans:integer);
var
xstartout,ystartout,xendout,yendout:integer;
begin
xstartout:=xstart+xtrans;
ystartout:=ystart+ytrans;
xendout:=xend+xtrans;
yendout:=yend+ytrans;
garis_DDA(xstart,ystart,xend,yend);
garis_DDA(xstartout,ystartout,xendout,yendout);
end;
procedure scaleLine(xstart,ystart,xend,yend,scale:integer);
var
xstartout,ystartout,xendout,yendout:integer;
begin
xstartout:=xstart*scale;
ystartout:=ystart*scale;
xendout:=xend*scale;
yendout:=yend*scale;
garis_DDA(xstart,ystart,xend,yend);
garis_DDA(xstartout,ystartout,xendout,yendout);
end;
procedure rotasigaris(xstart,ystart,xend,yend,xtengah,ytengah:integer;angle:real);
var xstartout,ystartout,xendout,yendout:integer;
begin
xstartout:=round((xtengah+((xstart-xtengah)*cos(angle)))-((ystart-ytengah)*sin(angle)));
ystartout:=round((ytengah+((xstart-xtengah)*sin(angle)))-((ystart-ytengah)*cos(angle)));
xendout:=round((xtengah+((xend-xtengah)*cos(angle)))-((yend-ytengah)*sin(angle)));
yendout:=round((ytengah+((xend-xtengah)*sin(angle)))-((yend-ytengah)*cos(angle)));
garis_DDA(xstart,ystart,xend,yend);
garis_DDA(xstartout,ystartout,xendout,yendout);
end;
begin
clrscr;
input;
writeln(”);
writeln(‘****LIST MENU***’);
writeln(”);
writeln(‘[1]. Pembentukan garis DDA’);
writeln(‘[2]. Translasi’);
writeln(‘[3]. Penskalaan’);
writeln(‘[4]. Rotasi Garis’);
write(‘masukkan pilihan anda:’);readln(pilih);
case pilih of
‘1’:
begin
init;
garis_DDA(x1,y1,x2,y2);
readln;
closegraph;
end;
‘2’:
begin
write(‘masukkan xtrans:’);readln(xtrans);
write(‘masukkan ytrans:’);readln(ytrans);
init;
transLine(x1,y1,x2,y2,xtrans,ytrans);
readln;
closegraph;
end;
‘3’:
begin
write(‘masukkan skala:’);readln(skala);
init;
scaleLine(x1,y1,x2,y2,skala);
readln;
closegraph;
end;
‘4’:
begin
write(‘masukkan x pusat:’);readln(xpst);
write(‘masukkan y pusat:’);readln(ypst);
write(‘masukkan derajat:’);readln(derajat);
init;
rotasigaris(x1,y1,x2,y2,xpst,ypst,derajat);
readln;
closegraph;
end;
end;
end.