Re: flood fills
- From: Calum Benson <calum benson sun com>
- To: Bryan Brown <bbrown saltmine radix net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: flood fills
- Date: 18 Dec 2002 16:38:58 +0000
On Wed, 2002-12-18 at 16:18, Bryan Brown wrote:
In the absence of such a Gtk function I've written my own rather
unsophisticated function to do it, but it doesn't completely fill regions
of arbitrary shape in one swell foop the way the Amiga did.
I don't know how the Amiga did it either, but the general algorithm for
flood-filling any arbitrary enclosed shape starting from some interior
point (x,y) is actually pretty easy:
floodFill (x,y, boundaryColour, fillColour)
{
if pixel(x,y) != boundaryColour
{
set pixel(x,y)=fillColour;
floodFill(x+1, y, boundaryColour, fillColour);
floodFill(x-1, y, boundaryColour, fillColour);
floodFill(x, y-1, boundaryColour, fillColour);
floodFill(x, y+1, boundaryColour, fillColour);
}
}
Obviously the downside is that it's highly recursive, so if you're
filling big areas you don't want to be running on a machine that's low
on memory...
Cheeri,
Calum.
--
CALUM BENSON, Usability Engineer Sun Microsystems Ireland
mailto:calum benson sun com GNOME Desktop Group
http://ie.sun.com +353 1 819 9771
Any opinions are personal and not necessarily those of Sun Microsystems
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]