计算机图形学的实验,vb编程,一下午没搞定,关于区域填充,求大神搭救 20
实验四区域填充一、实验目的认识区域填充的基本原理并编程实现区域填充的基本算法二、实验任务1.使用Line方法绘制多边形(自定义多边形顶点)2.编写区域填充函数3.尝试编程...
实验四 区域填充
一、实验目的
认识区域填充的基本原理并编程实现区域填充的基本算法
二、实验任务
1.使用Line方法绘制多边形(自定义多边形顶点)
2.编写区域填充函数
3.尝试编程实现种子填充算法
三、主要代码
'新建直线类
'直线方程为:ax+by+c=0
Private Type LineType
a As Single
b As Single
c As Single
maxy As Single
miny As Single
End Type
'定义各条线段
Dim eLine() As LineType
'求扫描线与多边形边的交点 X坐标
Private Function IntersectionP(TempLine As LineType, ByVal tempy As Single) As Single
'输入的扫描线与多边形边没有交点
If (tempy < TempLine.miny) Or (tempy > TempLine.maxy) Then IntersectionP = 0
Else
'ax+by+c=0
IntersectionP = ((-1) * TempLine.b * tempy - TempLine.c) / TempLine.a
End If
End Function
'设置扫描线的起始和终止位置(自定义)
StartY = (Int((GetMinY) / CSng(Text1.Text)) + 1) * CSng(Text1.Text)
EndY = Int((GetMaxY) / CSng(Text1.Text)) * CSng(Text1.Text)
'开始循环
For scanY = StartY To EndY Step CSng(Text1.Text)
ScanNum = 0
'1、求扫描线与边的交点
For i = 1 To PointNum
temp = IntersectionP(eLine(i), scanY)
If temp <> 0 Then
ScanNum = ScanNum + 1
ScanPoint(ScanNum) = temp
End If
Next
'2、排序:把所有交点按递增顺序进行排序
Dim ii As Integer, jj As Integer
Dim tempp As Single
For ii = 1 To ScanNum - 1
For jj = ii + 1 To ScanNum
If ScanPoint(ii) > ScanPoint(jj) Then
tempp = ScanPoint(ii)
ScanPoint(ii) = ScanPoint(jj)
ScanPoint(jj) = tempp
End If
Next
Next
'3、交点配对:第一点与第二点,第三点与第四点(令下列循环 Step为 2)
'4、区间画线:
For i = 1 To ScanNum Step 2
Picture1.Line (ScanPoint(i), scanY)-(ScanPoint(i + 1), scanY)
Next
Next '结束循环
这是指导书上的图片 展开
一、实验目的
认识区域填充的基本原理并编程实现区域填充的基本算法
二、实验任务
1.使用Line方法绘制多边形(自定义多边形顶点)
2.编写区域填充函数
3.尝试编程实现种子填充算法
三、主要代码
'新建直线类
'直线方程为:ax+by+c=0
Private Type LineType
a As Single
b As Single
c As Single
maxy As Single
miny As Single
End Type
'定义各条线段
Dim eLine() As LineType
'求扫描线与多边形边的交点 X坐标
Private Function IntersectionP(TempLine As LineType, ByVal tempy As Single) As Single
'输入的扫描线与多边形边没有交点
If (tempy < TempLine.miny) Or (tempy > TempLine.maxy) Then IntersectionP = 0
Else
'ax+by+c=0
IntersectionP = ((-1) * TempLine.b * tempy - TempLine.c) / TempLine.a
End If
End Function
'设置扫描线的起始和终止位置(自定义)
StartY = (Int((GetMinY) / CSng(Text1.Text)) + 1) * CSng(Text1.Text)
EndY = Int((GetMaxY) / CSng(Text1.Text)) * CSng(Text1.Text)
'开始循环
For scanY = StartY To EndY Step CSng(Text1.Text)
ScanNum = 0
'1、求扫描线与边的交点
For i = 1 To PointNum
temp = IntersectionP(eLine(i), scanY)
If temp <> 0 Then
ScanNum = ScanNum + 1
ScanPoint(ScanNum) = temp
End If
Next
'2、排序:把所有交点按递增顺序进行排序
Dim ii As Integer, jj As Integer
Dim tempp As Single
For ii = 1 To ScanNum - 1
For jj = ii + 1 To ScanNum
If ScanPoint(ii) > ScanPoint(jj) Then
tempp = ScanPoint(ii)
ScanPoint(ii) = ScanPoint(jj)
ScanPoint(jj) = tempp
End If
Next
Next
'3、交点配对:第一点与第二点,第三点与第四点(令下列循环 Step为 2)
'4、区间画线:
For i = 1 To ScanNum Step 2
Picture1.Line (ScanPoint(i), scanY)-(ScanPoint(i + 1), scanY)
Next
Next '结束循环
这是指导书上的图片 展开
展开全部
已经修改完成,请采纳:
Option Base 1
Dim a(10) As Integer
Private Sub command1_click()
Dim n As Integer
List1.Clear
Randomize
Do
t = Int(90 * Rnd) + 10
For i = 1 To n
If t = a(i) Then Exit For
Next i
If i = n + 1 Then
n = n + 1
a(n) = t
List1.AddItem t
End If
Loop Until n >= 10
List1.AddItem "n=" & n
End Sub
Private Sub command2_click()
Dim b(10) As Integer
List2.Clear
For i = 1 To 10
b(i) = 1
Next i
For i = 1 To 10
For j = 1 To 10
If a(j) > a(i) Then
b(i) = b(i) + 1
End If
Next j
Next i
For i = 1 To 10
List2.AddItem b(i)
Next i
End Sub
Option Base 1
Dim a(10) As Integer
Private Sub command1_click()
Dim n As Integer
List1.Clear
Randomize
Do
t = Int(90 * Rnd) + 10
For i = 1 To n
If t = a(i) Then Exit For
Next i
If i = n + 1 Then
n = n + 1
a(n) = t
List1.AddItem t
End If
Loop Until n >= 10
List1.AddItem "n=" & n
End Sub
Private Sub command2_click()
Dim b(10) As Integer
List2.Clear
For i = 1 To 10
b(i) = 1
Next i
For i = 1 To 10
For j = 1 To 10
If a(j) > a(i) Then
b(i) = b(i) + 1
End If
Next j
Next i
For i = 1 To 10
List2.AddItem b(i)
Next i
End Sub
追问
光这些还是不会啊,求完整代码,不要只给一部分啊,从画多边形到填充,最好再有点注释,我是业余选手啊。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询