Here's another pixel flood fill routine I did a while back for you to look over...
Graphics 1024,768,32,1
SetBuffer FrontBuffer()
Global screen_width = GraphicsWidth()
Global screen_height = GraphicsHeight()
cx = screen_width / 2
cy = screen_height / 2
r# = 10
For count = 0 To 360 * 20
x1# = cx + Cos(count) * r#
y1# = cy + Sin(count) * r#
If x2# > 0 And y2# > 0 Then Line x1,y1,x2,y2
x2# = x1#
y2# = y1#
r# = r# + .05
Next
Type fill
Field x
Field y
Field d
End Type
match_red = 0
match_green = 0
match_blue = 0
fill_red = 255
fill_green = 0
fill_blue = 0
floodfill(10,10,((match_red Shl 16) Or (match_green Shl 8) Or match_blue),((fill_red Shl 16) Or (fill_green Shl 8) Or fill_blue))
While Not KeyHit(1)
Wend
End
Function floodfill(x,y,m,fc)
m = ReadPixel(x,y)
flood.fill = New fill
flood\x = x
flood\y = y
done = False
LockBuffer FrontBuffer()
While done = False
done = True
For flood.fill = Each fill
done = False
x = flood\x
y = flood\y
c = ReadPixelFast(x,y)
Delete flood
If c = m
WritePixelFast x,y,fc
If y > 0
If ReadPixelFast(x,y - 1) = m
flood.fill = New fill
flood\x = x
flood\y = y - 1
End If
End If
If y < screen_height - 2
If ReadPixelFast(x,y + 1) = m
flood.fill = New fill
flood\x = x
flood\y = y + 1
End If
End If
If x > 0
If ReadPixelFast(x - 1,y) = m
flood.fill = New fill
flood\x = x - 1
flood\y = y
End If
End If
If x < screen_width - 2
If ReadPixelFast(x + 1,y) = m
flood.fill = New fill
flood\x = x + 1
flood\y = y
End If
End If
End If
Next
Wend
UnlockBuffer FrontBuffer()
End Function
|