Tugas Mata Kuliah Komputer Grafik

Disusun Oleh : Sigit Rossandi U ( 360763013 )

SEKOLAH TINGGI MANAJEMEN INFORMATIKA DAN KOMPUTER INDONESIA MANDIRI
Jl. Jakarta No. 79 Bandung 40272Telp. 022-7272672, 022-7208180 Fax. 022-7271693 E-mail: Info@stmik-im.ac.id Tugas 1 Algoritma DDA

Program Algoritma DDA
uses graph,crt; var x1,x2,y1,y2:integer; 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 drawLine(xa,ya,xb,yb:integer); var xend,k:integer; dx,dy:real; x_inc,y_inc,x,y:real; begin dx:= abs(xb-xa); dy:= abs(yb-ya); x:=xa; y:=yb; if abs(dx) > abs(dy) then xend:=round(abs(dx)) else xend:=round(abs(dy)); x_inc:=dx/xend; y_inc:=dy/xend; putPixel(round(x),round(y),50); for k:=1 to xend do begin x:=x+x_inc; y:=y+y_inc; putPixel(round(x),round(y),50); end; end; begin writeln; writeln('***********************'); writeln(' Menampilkan Garis DDA '); writeln('***********************'); Writeln; write('masukkan x1:');readln(x1); write('masukkan y1:');readln(y1); write('masukkan x2:');readln(x2); write('masukkan y2:');readln(y2); init; drawLine(x1,y1,x2,y2); readkey; destroy;

end.

Algoritma Bressenham

Program Algoritma Bressenham
uses graph,crt; var x1,x2,y1,y2:integer; 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 DrawBressLine(xa,ya,xb,yb:integer); var

dx,p,dy,xEnd:integer; x,y:real; begin dx:= abs(xb-xa); dy:= abs(yb-ya); p:=2*dy-dx; if xa > xb then begin x:=xb; y:=yb; xEnd:=xa; end else begin x:=xa; y:=ya; xEnd:=xb; end; putPixel(round(x),round(y),50); while x < xEnd do begin x:=x+1; if p < 0 then p:=p+(2*dy) else begin y:=y+1; p:=p+(2*(dy-dx)); end; putPixel(round(x),round(y),50); end; end; begin writeln; writeln('******************************'); writeln(' Menampilkan Garis Bressenham '); writeln('******************************'); Writeln; write('masukkan x1:');readln(x1); write('masukkan y1:');readln(y1); write('masukkan x2:');readln(x2); write('masukkan y2:');readln(y2); init; DrawBressLine(x1,y1,x2,y2); readkey; destroy; end.