Floodfill geht doch so (peudocode):
Delphi-Quellcode:
Procedure FloodFill (Canvas : TCanvas; P : TPoint; NewColor : TColor);
Var
q : TPoint;
begin
Foreach Neighpor q of P do
if not visited[q] then begin
visited[q] := True;
Canvas.Pixel[q.x, q.y] := NewColor;
FloodFill(Canvas, q, NewColor);
end
end
Eine iterative Umformung ginge so:
Delphi-Quellcode:
Procedure FloodFill (Canvas : TCanvas; P : TPoint; NewColor : TColor);
Var
worktable: Stack of TPoint;
Q : TPoint;
begin
worktable.push(p):
while not worktable.IsEmpty do begin
q := worktable.pop;
if not visited[q] then begin
visited[q] := True;
Canvas.Pixel[q.x, q.y] := NewColor;
worktable.push(q);
end
end
end