使用Bresenham算法画圆,调试~
编写使用Bresenham算法画圆,为什么执行的时候老是溢出?不知道问题出在哪里~帮忙 谢谢Bresenham算法代码:
Private Sub lineBresenham(x1, y1, x2, y2)
Dim m, deltaX, deltaY, e As Double
Dim i, x, y As Integer
e = 0
If Abs(deltaX) >= Abs(deltaY) Then
m = deltaY / CDbl(deltaX)
For i = 0 To Abs(deltaX)
Picture1.PSet (x, y)
x = x + Sgn(deltaX)
e = e + Abs(m)
If e > 0 Then
y = y + Sgn(deltaX)
e = e - 1
End If
Next i
ElseIf Abs(deltaX) = 0 Then
For i = o To Abs(deltaY)
Picture1.PSet (x, y)
y = y + Sgn(deltaY)
Next i
Else
m = deltaX / CDbl(deltaY)
For i = 0 To Abs(deltaY)
Picture1.PSet (x, y)
y = y + Sgn(deltaY)
e = e + Abs(m)
If e > 0 Then
x = x + Sgn(deltaX)
e = e - 1
End If
Next i
End If
End Sub
其他的:
Dim command As Integer
Dim x1, y1 As Integer
Dim x2, y2 As Integer
Dim x0, y0 As Integer
Dim press As Boolean
Dim xnow, ynow As Integer
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
press = True
Picture1.DrawMode = 7
x0 = x
y0 = y
xnow = x
ynow = y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If press = True Then
Call lineBresenham(x0, y0, xnow, ynow)
Call lineBresenham(x0, y0, x, y)
xnow = x
ynow = y
end if
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Picture1.DrawMode = 13
press = False
Call lineBresenham(x0, y0, x, y)
End Sub