This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Tampilkan postingan dengan label Komputer Grafik. Tampilkan semua postingan
Tampilkan postingan dengan label Komputer Grafik. Tampilkan semua postingan

Kamis, 08 Maret 2012

Komputer Grafik - Membuat Garis dengan Metode DDA

Desain Form
Desain Form Program
Properties
Nama Atribut Nilai
Text1 (TextBox) Name txtAwal
Text2 (TextBox) Name txtAkhir
Command1 (CommandButton) Name cmdDDA
Caption DDA
List1 (ListBox) Name lisOutput
Label1 Caption Nilai Awal
Label2 Caption Nilai Akhir
Picture1 (PictureBox) ScaleMode 3 - Pixel
Name picOut

Source Code
Private Sub cmdDDA_Click()
'Deklarasi variabel
Dim awal() As String
Dim akhir() As String
Dim x As Double, y As Double
Dim dx As Integer, dy As Integer
Dim x1 As Integer, y1 As Integer
Dim x2 As Integer, y2 As Integer
Dim step As Integer
Dim x_inc As Double, y_inc As Double
Dim k As Integer
'Pecah input awal dan akhir
awal = Split(txtAwal.Text, ",")
akhir = Split(txtAkhir.Text, ",")
'Masukkan hasil pemecahan ke nilai x dan y
x1 = Val(awal(0))
y1 = Val(awal(1))
x2 = Val(akhir(0))
y2 = Val(akhir(1))
'Hitung nilai dx dan dy
dx = x2 - x1
dy = y2 - y1
'Tentukan nilai titik awal
x = x1
y = y1
'Menentukan nilai step
If Abs(dx) > Abs(dy) Then
    step = Abs(dx)
Else
    step = Abs(dy)
End If
'Hitung increment
x_inc = dx / step
y_inc = dy / step
'Membersihkan picture box dan list box
picOut.Cls
listOutput.Clear
'Masukkan nilai titik awal
picOut.PSet (Fix(x), Fix(y))
listOutput.AddItem "x0=" & x & ", y0=" & y
'Masukkan nilai titik yang lain hingga akhir
For k = 0 To step - 1
    x = x + x_inc
    y = y + y_inc
    listOutput.AddItem "x" & (k + 1) & "=" & x & ", y" & (k + 1) & "=" & y
    picOut.PSet (Fix(x), Fix(y))
Next k
End Sub

Hasil Running
Hasil Running Program