Results 1 to 16 of 16

Thread: antialiased line...

Threaded View

  1. #15
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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 IntegerByVal y0 As IntegerByVal x1 As IntegerByVal y1 As IntegerByVal 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 0Then
       dY 
    = -dY
       stepY 
    = -1
      
    Else
       
    stepY 1
      End 
    If
      If (
    dX 0Then
        dX 
    = -dX
        stepX 
    = -1
      
    Else
        
    stepX 1
      End 
    If
      
    dY dY 2
      dX 
    dX 2

      Me
    .PSet (x0y0), Color
      
            
    If (dX dYThen
              Fraction 
    dY - (dX 2)
              While (
    x0 <> x1)
                If (
    Fraction >= 0Then
                  y0 
    y0 stepY
                  Fraction 
    Fraction dX
                End 
    If
                
    x0 x0 stepX
                Fraction 
    Fraction dY
                Me
    .PSet (x0y0), Color
              Wend
            
    Else
              
    Fraction dX - (dY 2)
              While (
    y0 <> y1)
                If (
    Fraction >= 0Then
                  x0 
    x0 stepX
                  Fraction 
    Fraction dY
                End 
    If
                
    y0 y0 stepY
                Fraction 
    Fraction dX
                Me
    .PSet (x0y0), Color
              Wend
            End 
    If
    End Sub

    Private Sub Form_MouseDown(Button As IntegerShift As IntegerAs SingleAs Single)
      
    lineBresenham XYRnd Me.ScaleWidthRnd ScaleHeightRnd * &HFFFFFF
    End Sub 
    Last edited by Mad Compie; Sep 9th, 2001 at 06:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width