| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 626 人关注过本帖
标题:使用Bresenham算法画圆,调试~
只看楼主 加入收藏
adadejia
Rank: 1
来 自:云南
等 级:新手上路
帖 子:12
专家分:0
注 册:2009-2-26
结帖率:100%
收藏
 问题点数:0 回复次数:1 
使用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
搜索更多相关主题的帖子: Bresenham 算法 调试 
2009-10-13 18:55
adadejia
Rank: 1
来 自:云南
等 级:新手上路
帖 子:12
专家分:0
注 册:2009-2-26
收藏
得分:0 
我居然没有分可以送,愧疚啊~
2009-10-13 18:56
快速回复:使用Bresenham算法画圆,调试~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020472 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved