Here some code to apply Jack Bresenham's non-AA line algorithm:
I rewrote it from C (as seen in http://www.cs.unc.edu/~mcmillan/com...ure6/Lines.htmlmy ) to VB:
PHP Code:
Private Sub Form_Load()
Me.ScaleMode = vbPixels
End Sub
Public Sub lineBresenham(ByVal x0 As Integer, ByVal y0 As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal Color As Long)
Dim dY As Integer
Dim dX As Integer
Dim stepX As Integer
Dim stepY As Integer
Dim Fraction As Integer
dY = y1 - y0
dX = x1 - x0
If (dY < 0) Then
dY = -dY
stepY = -1
Else
stepY = 1
End If
If (dX < 0) Then
dX = -dX
stepX = -1
Else
stepX = 1
End If
dY = dY * 2
dX = dX * 2
Me.PSet (x0, y0), Color
If (dX > dY) Then
Fraction = dY - (dX \ 2)
While (x0 <> x1)
If (Fraction >= 0) Then
y0 = y0 + stepY
Fraction = Fraction - dX
End If
x0 = x0 + stepX
Fraction = Fraction + dY
Me.PSet (x0, y0), Color
Wend
Else
Fraction = dX - (dY \ 2)
While (y0 <> y1)
If (Fraction >= 0) Then
x0 = x0 + stepX
Fraction = Fraction - dY
End If
y0 = y0 + stepY
Fraction = Fraction + dX
Me.PSet (x0, y0), Color
Wend
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lineBresenham X, Y, X + Rnd * Me.ScaleWidth, Y + Rnd * ScaleHeight, Rnd * &HFFFFFF
End Sub




Reply With Quote