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
U.S. presidential election, 1804

... King (14) Other elections: 1792, 1796, 1800, 1804, 1808, 1812, 1816 Source: U.S. Office of the Federal R ...

 
 
 
This page was created in 26.6 ms