PDA

View Full Version : logic help


mk001
Feb2-06, 03:41 AM
help - this is visual basic code that deals with motion
can someone with some good math background pleas look it over and
let me know the logic
please comment
thanks




Private Sub fillRegion(px As Integer, py As Integer, depth As Integer, ByRef minX As Integer, ByRef maxX As Integer, ByRef minY As Integer, ByRef maxY As Integer)
'fills a region with the given colour


If (motion(px, py, 0)) And (motion(px, py, 1) = 0) Then

motion(px, py, 1) = True
RegionArea = RegionArea + 1

If (px < minX) Then
minX = px
End If
If (px > maxX) Then
maxX = px
End If
If (py < minY) Then
minY = py
End If
If (py > maxY) Then
maxY = py
End If

If (depth < 100) Then

If (py > 0) Then
Call fillRegion(px, py - 1, depth + 1, minX, maxX, minY, maxY)
End If

If (px < MotionResolution - 1) And (py > 0) Then
Call fillRegion(px + 1, py - 1, depth + 1, minX, maxX, minY, maxY)
End If

If (px < MotionResolution - 1) Then
Call fillRegion(px + 1, py, depth + 1, minX, maxX, minY, maxY)
End If

If (px < MotionResolution - 1) And (py < MotionResolution - 2) Then
Call fillRegion(px + 1, py + 1, depth + 1, minX, maxX, minY, maxY)
End If

If (py < MotionResolution - 1) Then
Call fillRegion(px, py + 1, depth + 1, minX, maxX, minY, maxY)
End If

If (px > 0) Then
Call fillRegion(px - 1, py, depth + 1, minX, maxX, minY, maxY)
End If

If (px > 0) And (py > 0) Then
Call fillRegion(px - 1, py - 1, depth + 1, minX, maxX, minY, maxY)
End If

If (px > 0) And (py < MotionResolution - 1) Then
Call fillRegion(px - 1, py + 1, depth + 1, minX, maxX, minY, maxY)
End If

If (px < MotionResolution - 1) And (py < MotionResolution - 1) Then
Call fillRegion(px + 1, py + 1, depth + 1, minX, maxX, minY, maxY)
End If

End If
End If
End Sub