PROGRAM GARIS PADA PASCAL
uses crt, graph;
var driver,mode:integer;
x1,y1,x2,y2:integer;
step,k:integer;
dx,dy:real;
xm,ym,x,y:real;
procedure utama;
begin
clrscr;
driver:=detect;
InitGraph(driver,mode,'');
end;
procedure Input;
begin
writeln('Program Menggambar Garis Dengan Algoritma 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;
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),white);
for k:=1 to step do
begin
x:=x+xm;
y:=y+ym;
putPixel(round(x),round(y),white);
end;
end;
begin
input;
utama;
Garis_DDA;
readln;
end.
Atau dengan cara :
uses graph, crt;
var q,w,e,r: integer;
procedure init;
var gd, gm : integer;
begin
gm :=detect; gd:=0;
initgraph (gd,gm,'');
if graphresult <> grok then
begin
writeln('graph driver ',gd,' graph mode ',gm,'not supported');
halt (1);
end;
end;
procedure destroy;
begin
closegraph;
end;
procedure drawline (xstart,ystart,xend,yend:integer);
var
step,k:integer;
dx,dy:real;
x_inc,y_inc,x,y:real;
begin
dx:=xend-xstart;
dy:=yend-ystart;
x:=xstart;
y:=ystart;
if abs (dx) > abs (dy) then
step:=round (abs(dx))
else
step:=round (abs(dy));
x_inc:= dx/step;
y_inc:= dy/step;
putpixel (round (x), round (y), 30);
for k:=1 to step do
begin
x:=x+x_inc;
y:=y+y_inc;
putpixel (round (x), round (y),30);
end;
end;
begin
clrscr;
write('koordinat 1 =') ; readln (q);
write('koordinat 2 =') ; readln (w);
write('panjang garis =') ; readln (e);
write('koordinat 3 =') ; readln (r);
begin
init;
drawline (q,w,e,r);
readkey;
destroy;
end;
end.
output :
Sunday, 11 October 2009
PROGRAM GARIS PADA PASCAL
Subscribe to:
Post Comments (Atom)
7 comments:
kak, programnya masih error neh, pada "uses crt, graph" file not found 0.15 mksdny apa ka??? terimakasihhh :)
kamu file save nya taruh di bin
baru di run
kak, programnya error. .
runtime error 200 at 1077:02d1
kenapa nih kaks. .
mohon pencerahan. . thanks. .
il program elo masih eror
ga begitu kali seharusnya
hahahahahahahaha
graphics not initialized,, bikin gimana kak.
mantap bos thx ya programnya lancar..
Grapich nya g keluar biji mana tu??
:)) :)] ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} ~x( :-t b-( :-L x( =))
Post a Comment