```
Sub FindVector( M as matrix, StartingPoint as Pxy, dir as int )
Dim CurrentPoint as Pxy
CurrentPoint.initialize(Pxy.x,Pxy.y)
Dim myVector as Vector
myVector.initialize(0,dir)
'pseudocode
if dir=0 then
incx=1:incy=0
else if dir=90 then
incx=0:incy=1
else if dir=180 then
incx=-1:incy=0
else if dir=270 then
incx=0:incy=-1
endif
while Matrix(CurrentPoint.x,CurrentPoint.y)>0
myvec.len=myvec.len+1
CurrentPoint.x = CurrentPoint.x + incx
CurrentPoint.y = CurrentPoint.y + incy
Loop
return myvec
end sub
Sub FindAllVectors
Dim myPoint as Pxy
myPoint.initialize(1,1)
Dim myVec1 as Vector = FindVector( myMatrix, myPoint, 0)
myPoint.x = myPoint.x + (myVec1.len -1) 'or exit if len==0
Dim myVec2 as Vector = FindVector( myMatrix, myPoint, 90)
myPoint.y = myPoint.y + (myVec2.len-1)'or exit if len==0
Dim myVec3 as Vector = FindVector( myMatrix, myPoint, 180)
myPoint.x = myPoint.x - (myVec3.len-1)'or exit if len==0
Dim myVec4 as Vector = FindVector( myMatrix, myPoint, 270)
end Sub
```