<s>
Flood	B-Protocol
fill	I-Protocol
,	O
also	O
called	O
seed	B-Protocol
fill	I-Protocol
,	O
is	O
a	O
flooding	B-Protocol
algorithm	I-Protocol
that	O
determines	O
and	O
alters	O
the	O
area	O
connected	O
to	O
a	O
given	O
node	O
in	O
a	O
multi-dimensional	O
array	B-Data_Structure
with	O
some	O
matching	O
attribute	O
.	O
</s>
<s>
It	O
is	O
used	O
in	O
the	O
"	O
bucket	O
"	O
fill	O
tool	O
of	O
paint	B-Application
programs	I-Application
to	O
fill	O
connected	O
,	O
similarly-colored	O
areas	O
with	O
a	O
different	O
color	O
,	O
and	O
in	O
games	O
such	O
as	O
Go	O
and	O
Minesweeper	B-Application
for	O
determining	O
which	O
pieces	O
are	O
cleared	O
.	O
</s>
<s>
A	O
variant	O
called	O
boundary	B-Protocol
fill	I-Protocol
uses	O
the	O
same	O
algorithms	O
but	O
is	O
defined	O
as	O
the	O
area	O
connected	O
to	O
a	O
given	O
node	O
that	O
does	O
not	O
have	O
a	O
particular	O
attribute	O
.	O
</s>
<s>
Note	O
that	O
flood	B-Protocol
filling	I-Protocol
is	O
not	O
suitable	O
for	O
drawing	O
filled	O
polygons	O
,	O
as	O
it	O
will	O
miss	O
some	O
pixels	O
in	O
more	O
acute	O
corners	O
.	O
</s>
<s>
Instead	O
,	O
see	O
Even-odd	B-Algorithm
rule	I-Algorithm
and	O
Nonzero-rule	B-Algorithm
.	O
</s>
<s>
The	O
algorithm	O
looks	O
for	O
all	O
nodes	O
in	O
the	O
array	B-Data_Structure
that	O
are	O
connected	O
to	O
the	O
start	O
node	O
by	O
a	O
path	O
of	O
the	O
target	O
color	O
and	O
changes	O
them	O
to	O
the	O
replacement	O
color	O
.	O
</s>
<s>
The	O
earliest-known	O
,	O
implicitly	O
stack-based	O
,	O
recursive	O
,	O
four-way	O
flood-fill	O
implementation	O
goes	O
as	O
follows	O
:	O
</s>
<s>
Though	O
easy	O
to	O
understand	O
,	O
the	O
implementation	O
of	O
the	O
algorithm	O
used	O
above	O
is	O
impractical	O
in	O
languages	O
and	O
environments	O
where	O
stack	B-Application
space	O
is	O
severely	O
constrained	O
(	O
e.g.	O
</s>
<s>
Microcontrollers	B-Architecture
)	O
.	O
</s>
<s>
Moving	O
the	O
recursion	O
into	O
a	O
data	O
structure	O
(	O
either	O
a	O
stack	B-Application
or	O
a	O
queue	B-Application
)	O
prevents	O
a	O
stack	B-Error_Name
overflow	I-Error_Name
.	O
</s>
<s>
It	O
is	O
similar	O
to	O
the	O
simple	O
recursive	O
solution	O
,	O
except	O
that	O
instead	O
of	O
making	O
recursive	O
calls	O
,	O
it	O
pushes	O
the	O
nodes	O
onto	O
a	O
stack	B-Application
or	O
queue	B-Application
for	O
consumption	O
,	O
with	O
the	O
choice	O
of	O
data	O
structure	O
affecting	O
the	O
proliferation	O
pattern	O
:	O
</s>
<s>
Set	O
Q	O
to	O
the	O
empty	O
queue	B-Application
or	O
stack	B-Application
.	O
</s>
<s>
Check	O
and	O
set	O
each	O
node	O
's	O
pixel	O
color	O
before	O
adding	O
it	O
to	O
the	O
stack/queue	O
,	O
reducing	O
stack/queue	O
size	O
.	O
</s>
<s>
Interleave	O
two	O
or	O
more	O
copies	O
of	O
the	O
code	O
with	O
extra	O
stacks/queues	O
,	O
to	O
allow	O
out-of-order	B-General_Concept
processors	I-General_Concept
more	O
opportunity	O
to	O
parallelize	O
.	O
</s>
<s>
Uses	O
a	O
lot	O
of	O
memory	O
,	O
particularly	O
when	O
using	O
a	O
stack	B-Application
.	O
</s>
<s>
Using	O
a	O
stack	B-Application
explores	O
spans	O
depth	O
first	O
,	O
whilst	O
a	O
queue	B-Application
explores	O
spans	O
breadth	O
first	O
.	O
</s>
<s>
Two	O
common	O
ways	O
to	O
make	O
the	O
span	O
and	O
pixel-based	O
algorithms	O
support	O
pattern	O
filling	O
are	O
either	O
to	O
use	O
a	O
unique	O
color	O
as	O
a	O
plain	O
fill	O
and	O
then	O
replace	O
that	O
with	O
a	O
pattern	O
or	O
to	O
keep	O
track	O
(	O
in	O
a	O
2d	O
boolean	O
array	B-Data_Structure
or	O
as	O
regions	O
)	O
of	O
which	O
pixels	O
have	O
been	O
visited	O
,	O
using	O
it	O
to	O
indicate	O
pixels	O
are	O
no	O
longer	O
fillable	O
.	O
</s>
<s>
Regularly	O
,	O
a	O
span	O
has	O
to	O
be	O
compared	O
to	O
every	O
other	O
'	O
front	O
 '	O
in	O
the	O
queue	B-Application
,	O
which	O
significantly	O
slows	O
down	O
complicated	O
fills	O
.	O
</s>
<s>
A	O
method	O
exists	O
that	O
uses	O
essentially	O
no	O
memory	O
for	O
four-connected	B-Algorithm
regions	O
by	O
pretending	O
to	O
be	O
a	O
painter	O
trying	O
to	O
paint	O
the	O
region	O
without	O
painting	O
themselves	O
into	O
a	O
corner	O
.	O
</s>
<s>
For	O
case	O
#4	O
,	O
we	O
need	O
to	O
check	O
the	O
opposite	O
8-connected	B-Algorithm
corners	O
to	O
see	O
whether	O
they	O
are	O
filled	O
or	O
not	O
.	O
</s>
<s>
The	O
classic	O
recursive	O
flood	B-Protocol
fill	I-Protocol
algorithm	I-Protocol
was	O
available	O
on	O
the	O
Vicom	O
system	O
as	O
well	O
.	O
</s>
<s>
Version	O
0.46	O
of	O
Inkscape	B-Application
includes	O
a	O
bucket	B-Protocol
fill	I-Protocol
tool	O
,	O
giving	O
output	O
similar	O
to	O
ordinary	O
bitmap	O
operations	O
and	O
indeed	O
using	O
one	O
:	O
the	O
canvas	O
is	O
rendered	O
,	O
a	O
flood	B-Protocol
fill	I-Protocol
operation	O
is	O
performed	O
on	O
the	O
selected	O
area	O
and	O
the	O
result	O
is	O
then	O
traced	O
back	O
to	O
a	O
path	O
.	O
</s>
