Program Pascal DDA, Lingkaran,translasi,scaling

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
clrscr;
writeln(”:20,’Program Menggambar Garis Dengan DDA’);
writeln(”:20,’===================================’);
writeln;
write(”:15,’Masukkan nilai x1:’);
readln(x1);
write(”:15,’Masukkan nilai y1:’);
readln(y1);
write(”:15,’Masukkan nilai x2:’);
readln(x2);
write(”:15,’Masukkan nilai y2:’);
readln(y2);
writeln;
writeln;
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),white);
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
input;
clrscr;
writeln;
writeln;
writeln(”:20,’****Menu Pilihan***’);
writeln(”:15,'[1]. Pembentukan garis DDA’);
writeln(”:15,'[2]. Translasi’);
writeln(”:15,'[3]. Penskalaan’);
writeln(”:15,'[4]. Rotasi Garis’);
writeln(”:15,'[5]. Petunjuk Pogram’);
write(”:15,’Masukkan Pilihan Anda:’);readln(pilih);
writeln;
begin
clrscr;
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;
‘5’ :
begin
writeln(”:20,’Panduan Program’);
writeln(”:20,’===============’);
writeln(”:15,’1. Masukan nilai koordiatnya’);
writeln(”:15,’2. Menu pilihan yang akan digunakan’);
writeln(”:15,’3. Jika menu yang telah diinputkan, meminta inputan lagi’);
writeln(”:18,’maka inputkan nilainya’);
writeln(”:15,’4. Output Hasil, berupa garis’);
readln;
end;
end;
end;
end.

Gunakan Pascal 7.0 ( install) dan copy source code ke folder C:/ TP /bin lalu jalankan lewat DOS…selamat

mencoba goodluck!

~ oleh education2012 pada 06/12/2009.

 
%d blogger menyukai ini: