31 lines
1.1 KiB
Plaintext
31 lines
1.1 KiB
Plaintext
Procedure Floodfill(x,y,new_color)
|
|
old_color = Point(x,y)
|
|
NewList stack.POINT()
|
|
AddElement(stack()):stack()\x = x : stack()\y = y
|
|
While(LastElement(stack()))
|
|
x = stack()\x : y = stack()\y
|
|
DeleteElement(stack())
|
|
If Point(x,y) = old_color
|
|
Plot(x, y, new_color)
|
|
AddElement(stack()):stack()\x = x : stack()\y = y +1
|
|
AddElement(stack()):stack()\x = x : stack()\y = y -1
|
|
AddElement(stack()):stack()\x = x +1 : stack()\y = y
|
|
AddElement(stack()):stack()\x = x -1 : stack()\y = y
|
|
EndIf
|
|
Wend
|
|
EndProcedure
|
|
|
|
If OpenWindow(0, 0, 0, 200, 200, "Floodfill Beispiel", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
|
|
StartDrawing(WindowOutput(0))
|
|
Box(0, 0, 200, 200, RGB(255, 255, 255))
|
|
DrawingMode(#PB_2DDrawing_Outlined )
|
|
Circle(100, 100, 90, RGB(255 ,0,0)): Circle(120, 80, 30, RGB(255 ,0,0)): Circle(200,200, 70, RGB(255 ,0,0))
|
|
|
|
Floodfill(40,40,RGB(0 ,255,0))
|
|
|
|
StopDrawing()
|
|
Repeat
|
|
Event = WaitWindowEvent()
|
|
Until Event = #PB_Event_CloseWindow
|
|
EndIf
|