OptionExplicit Private cltStackX As Collection Private lTopX AsLong Private cltStackY As Collection Private lTopY AsLong Dim X%, Y% Const Vnumber =7'一共7个点 Const xMax =14'坐标最大值12 Const grid =400 PrivateSub Command1_Click()Sub Command1_Click() Form1.Cls Call DrawCoordinate Call DrawPset If Text1.Text <>""And Text2.Text <>""Then Call Fill(Text1.Text, Text2.Text) EndIf End Sub PrivateSub Form_Load()Sub Form_Load() Dim x0, y0, x1, y1 AsSingle x0 =-ScaleWidth /4 y0 = ScaleHeight -200 x1 = ScaleWidth *3/4-200 y1 =-200 Scale (x0 +1500, y0)-(x1 +1500, y1) Call Class_InitializeX Call Class_InitializeY End Sub PrivateSub Form_Activate()Sub Form_Activate() Dim X, Y AsInteger X =0 Y =0 Call DrawCoordinate '调用画格子过程 Call DrawPset End Sub PrivateSub DrawCoordinate()Sub DrawCoordinate() '画坐标方格 Dim i AsInteger For i =1To xMax +1 Line (0, Y)-(xMax * grid, Y) Line (X, 0)-(X, xMax * grid) X = X + grid Y = Y + grid Next End Sub PrivateSub DrawPset()Sub DrawPset() Dim i AsInteger DrawWidth =15'划笔粗细 For i =2To12 PSet (i * grid, 2* grid), vbBlue Next i For i =2To12 PSet (2* grid, i * grid), vbBlue Next i For i =2To12 PSet (12* grid, i * grid), vbBlue Next i For i =2To12 PSet (i * grid, 12* grid), vbBlue Next i DrawWidth =1: X =0: Y =0 End Sub PrivateSub Class_InitializeX()Sub Class_InitializeX() Set cltStackX =New Collection lTopX =0 End Sub PublicSub PushX()Sub PushX(data AsInteger) cltStackX.Add data, CStr(lTopX) lTopX = lTopX +1 End Sub PublicFunction PopX()Function PopX() AsInteger PopX = cltStackX.Item(lTopX) cltStackX.Remove (lTopX) lTopX = lTopX -1 End Function PublicFunction IsEmptyX()Function IsEmptyX() AsBoolean IsEmptyX = (lTopX <=0) End Function PrivateSub Class_InitializeY()Sub Class_InitializeY() Set cltStackY =New Collection lTopY =0 End Sub PublicSub PushY()Sub PushY(data AsInteger) cltStackY.Add data, CStr(lTopY) lTopY = lTopY +1 End Sub PublicFunction PopY()Function PopY() AsInteger PopY = cltStackY.Item(lTopY) cltStackY.Remove (lTopY) lTopY = lTopY -1 End Function PublicFunction IsEmptyY()Function IsEmptyY() AsBoolean IsEmptyY = (lTopY <=0) End Function PrivateSub Fill()Sub Fill(ptX AsInteger, ptY AsInteger) Dim Sign AsBoolean Dim xRight, xLeft AsInteger Dim xT, yT AsInteger Dim i AsInteger Dim counter AsDouble DrawWidth =15'划笔粗细 If ptX >2And ptX <12And ptY >2And ptY <12Then Sign =True EndIf If Sign =TrueThen PushX (ptX) PushY (ptY) DoWhile IsEmptyX =False '处理种子所在线 xT = PopX yT = PopY i = xT Do For counter =1To1000000 Next If Point(i * grid, yT * grid) = vbBlue Then ExitDo EndIf PSet (i * grid, yT * grid), vbRed '填充点 i = i +1 Loop i = xT Do For counter =1To1000000 Next If Point(i * grid, yT * grid) = vbBlue Then ExitDo EndIf PSet (i * grid, yT * grid), vbRed '填充点 i = i -1 Loop '处理下一条线 i = xT If Point(i * grid, (yT -1) * grid) <> vbBlue And Point(i * grid, (yT -1) * grid) <> vbRed Then Do If Point(i * grid, (yT -1) * grid) = vbBlue Then xLeft = i +1 PushX (xLeft) PushY (yT -1) ExitDo EndIf i = i -1 Loop EndIf '处理上一条线 i = xT If Point(i * grid, (yT +1) * grid) <> vbBlue And Point(i * grid, (yT +1) * grid) <> vbRed Then Do If Point(i * grid, (yT +1) * grid) = vbBlue Then xLeft = i +1 PushX (xLeft) PushY (yT +1) ExitDo EndIf i = i -1 Loop EndIf Loop Else MsgBox ("所用种子点超出正方形范围...") EndIf DrawWidth =1: X =0: Y =0 End Sub