HI 如何在可视基本阵列中存储简单的轮廓线?
示例:如果有一个5 x 5数组,则edge = 100,Center of array = 110.然后:
100 100 100 100 100
100 105 105 105 100
100 105 110 105 100
100 105 105 105 100
100 100 100 100 100
外圈= 100,1步内圈= 105然后中心= 110。
是否有这样做的通用例程?如果阵列是偶数(例如6 x 6)会发生什么? 6 x 6没有中心和奇数。
谢谢!
答案 0 :(得分:1)
这里有一些代码来创建数组:
Dim a(1 To 5, 1 To 5) As Integer
Private Sub SetRing(lvl As Long, dimSize As Long, value As Long)
Call SetHValues(lvl, dimSize, value)
Call SetVValues(lvl, dimSize, value)
End Sub
Private Sub SetHValues(lvl As Long, dimSize As Long, value As Long)
Dim i As Long, k As Long
If lvl > (dimSize / 2) + 1 Then Exit Sub
For i = lvl To dimSize - lvl + 1
' horizontal values'
a(lvl, i) = value
a(dimSize - lvl + 1, i) = value
Next
End Sub
Private Sub SetVValues(lvl As Long, dimSize As Long, value As Long)
Dim i As Long, k As Long
If lvl > (dimSize / 2) + 1 Then Exit Sub
For i = lvl To dimSize - lvl + 1
' vertical values'
a(i, lvl) = value
a(i, dimSize - lvl + 1) = value
Next
End Sub
要创建示例数组,您可以调用:
Call SetRing(1, 5, 100)
Call SetRing(2, 5, 105)
Call SetRing(3, 5, 110)