ini adalah coding'a.:
uses graph,crt;
var driver,mode:integer;
x1,y1,x2,y2:integer;
step,k:integer;
dx,dy:real;
xm,ym,x,y:real;
pil :integer;
men:integer;
label menu;
procedure utama;
begin
driver:=detect;
InitGraph(driver,mode,'');
end;
procedure Input;
begin
clrscr;
writeln('Program Menggambar Garis DIAGONAL');
writeln('<<=========================================>>');
writeln;
write('Masukkan Nilai x1: ');
readln(x1);
write('masukan nilai X2: ');
readln(x2);
write('Masukkan Nilai y1: ');
readln(y1);
write('Masukkan Nilai y2: ');
readln(y2);
end;
procedure Garis_diagonal;
begin
x1:=abs(x1);
x2:=abs(x2);
y1:=abs(y1);
y2:=abs(y2);
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),red);
for k:=1 to step do
begin
x:=x+xm;
y:=y+ym;
putPixel(round(x),round(y),red);
end;
end;
procedure hor;
begin
driver:=detect;
InitGraph(driver,mode,'');
end;
procedure inhor;
begin
clrscr;
writeln('Program Menggambar Garis');
writeln('<<=========================================>>');
writeln;
write('Masukkan Nilai x1: ');
readln(x1);
write('Masukkan Nilai y1: ');
readln(y1);
writeln('Masukan Nilai y2 : ');
readln(y2);
end;
procedure gahor;
begin
x1:=abs(x1);
y1:=abs(y1);
y2:=abs(y2);
dy:=y2-y1;
x:=x1;
y:=y1;
if abs(x) > abs(dy) then
step:=round(abs(x))
else
step:=round(abs(dy));
ym:=dy/step;
putPixel(round(x),round(y),yellow);
for k:=1 to step do
begin
y:=y+ym;
putPixel(round(x),round(y),yellow);
end;
end;
procedure ver;
begin
driver:=detect;
InitGraph(driver,mode,'');
end;
procedure inver;
begin
clrscr;
writeln('Program Menggambar Garis');
writeln('<<=========================================>>');
writeln;
write('Masukkan Nilai x1: ');
readln(x1);
writeln('Masukan Nilai x2: ');
readln(x2);
write('Masukkan Nilai y1: ');
readln(y1);
end;
procedure gaver;
begin
x1:=abs(x1);
x2:=abs(x2);
y1:=abs(y1);
y2:=abs(y2);
dx:=x2-x1;
x:=x1;
y:=y1;
if abs(dx) > abs(y) then
step:=round(abs(dx))
else
step:=round(abs(dy));
xm:=dx/step;
putPixel(round(x),round(y),green);
for k:=1 to step do
begin
x:=x+xm;
putPixel(round(x),round(y),green);
end;
end;
begin
menu:
clrscr;
writeln('-------menu-------');
writeln('==================');
writeln('1. vertikal ');
writeln('2. horizontal ');
writeln('3. diagonal ');
writeln('4. keluar ');
writeln('ukuran layar 1024 x 768 ');
writeln('untuk hasil yang maximal masukan kordinat 100-999');
writeln('masukan pilihan :');
readln(pil);
case pil of
1: begin
inhor;
hor;
gahor;
goto menu;
end;
2: begin
inver;
ver;
gaver;
goto menu;
end;
3: begin
input;
utama;
Garis_diagonal;
readln;
goto menu;
end;
4: begin
end;
end;
end.
output:
0 comments:
Post a Comment