[wxpython-users] FloodFill on OSX
Tim Roberts
timr at probo.com
Wed Apr 2 09:46:39 PDT 2008
On Wed, Apr 2, 2008 at 2:57 AM, Timothy Grant <timothy.grant at gmail.com>
wrote:
>
>> > I'm just mucking about with some wxPython code and am a bit flummoxed by
>> > this behavior..
>> >
>> > I have a window with a 'DARKGREY' grid painted on it. I simply want to
>> > colour the square on the grid I click in a different colour.
>> >
>> > dc =3D wx.PaintDC(self)
>> > dc.SetBrush(wx.Brush('BLUE'))
>> >
>> > print dc.Brush.GetColour()
>> > dc.BeginDrawing()
>> > if dc.FloodFill((w * GRIDSIZE) + 1, (h * GRIDSIZE) + 1,
>> > 'DARKGREY', wx.FLOOD_SURFACE):
>> > print "flood successful"
>> > else:
>> > print "flood not successful"
>> > dc.EndDrawing()
>> >
>> > The FloodFIll always prints "flood not successful" and I'm not sure what
>> > I'm doing wrong.
FloodFill is always an extremely expensive operation. It should only be
used as a last resort.
In order to implement a FloodFill, the driver has to read every pixel in
the flooding area. There is no shortcut here. It has to start at the
coordinate you give, then start reading pixels to the left and right
until it finds a different color. Then it has to move up to the
previous scanline, and search it for any areas that are the same color,
and so on up and down until it hits THOSE borders. It is PAINFULLY slow.
It is always better to compute the actual drawing region yourself and do
a straight paint.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the wxpython-users
mailing list