Encyclopedia > Bresenham's line algorithm Visual basic code

  Article Content

Bresenham's line algorithm Visual basic code

An example of Bresenham's line algorithm in Visual Basic follows. The "Swap" procedure is not shown.

 Private Sub BresLine(InitialX As Long, InitialY As Long, FinalX As Long, FinalY As Long)
    ' Bresenham's line algorithm for Microsoft Visual Basic 6.0
    ' Implementation by Robert Lee <rlee0001@maine.rr.com> July, 2002 Public Domain

    Dim Steep As Boolean
    Dim DeltaX As Long, DeltaY As Long, Delta As Long
    Dim StepX As Long, StepY As Long
    Dim Coord As Long

    Steep = False
    DeltaX = Abs(FinalX - InitialX)
    If (FinalX - InitialX) > 0 Then
        StepX = 1
    Else
        StepX = -1
    End If
    DeltaY = Abs(FinalY - InitialY)
    If (FinalY - InitialY) > 0 Then
        StepY = 1
    Else
        StepY = -1
    End If
    If DeltaY > DeltaX Then
        Steep = True
        Swap InitialX, InitialY
        Swap DeltaX, DeltaY
        Swap StepX, StepY
    End If
    Delta = (DeltaY * 2) - DeltaX
    For Coord = 0 To DeltaX
        If Steep Then
            Me.PSet (InitialY, InitialX)
        Else
            Me.PSet (InitialX, InitialY)
        End If
        While Delta >= 0
            InitialY = InitialY + StepY
            Delta = Delta - (DeltaX * 2)
        Wend
        InitialX = InitialX + StepX
        Delta = Delta + (DeltaY * 2)
    Next Coord
    Me.PSet (FinalX, FinalY)
 End Sub



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Northwest Harbor, New York

... them, 55.2% are married couples living together, 9.2% have a female householder with no husband present, and 30.7% are non-families. 22.6% of all households are made up of ...

 
 
 
This page was created in 44.3 ms