[comp.lang.pascal] TP5.5 FloodFill

clong@emerald.rutgers.edu (Chris Long) (09/30/90)

Has anyone else had problems with TP5.5's FloodFill?  I do a

  SetColor(2);
  for n:=0 to 20 do
    Line(n*20,0,n*20,400);
  for n:=0 to 20 do
    Line(0,n*20,400,n*20);

  SetColor(3);
  for n:=0 to 10 do
    FloodFill(n*20+10,10,2);

  SetColor(0);
  for n:=0 to 10 do
    FloodFill(n*20+10,10,2);

It draws the grid nicely and does the first set of fills, but the
next set of fills does nothing.

-Chris

ts@uwasa.fi (Timo Salmi) (09/30/90)

In article <Sep.29.14.48.07.1990.26812@emerald.rutgers.edu> clong@emerald.rutgers.edu (Chris Long) writes:
>
>Has anyone else had problems with TP5.5's FloodFill?  I do a
:
>
>  SetColor(0);
>  for n:=0 to 10 do
>    FloodFill(n*20+10,10,2);
>
:
>next set of fills does nothing.

There is a simple trick to test the fill locig.  Replace FloodFill
(temporarily) with PutPixel so that you can ascertain that your fill
seed is properly placed. 

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

clong@remus.rutgers.edu (Chris Long) (09/30/90)

In article <1990Sep29.202750.7797@uwasa.fi>, Timo Salmi writes:

> There is a simple trick to test the fill locig.  Replace FloodFill
> (temporarily) with PutPixel so that you can ascertain that your fill
> seed is properly placed. 

The seeds are properly placed.  Is it the case that FloodFill only
fills over the background?  If so, no mention of this is made in the
reference guide.

Incidentally, the object of the short bit of code posted is to
highlight (fill) certain locations on the grid and to then restore
them (fill with black).  Is there perhaps a better way of doing
this, i.e. one that works?

-Chris

ts@uwasa.fi (Timo Salmi) (09/30/90)

In article <Sep.29.18.03.09.1990.3842@remus.rutgers.edu> clong@remus.rutgers.edu (Chris Long) writes:
>In article <1990Sep29.202750.7797@uwasa.fi>, Timo Salmi writes:
>
>> There is a simple trick to test the fill locig.  Replace FloodFill
>> (temporarily) with PutPixel so that you can ascertain that your fill
>> seed is properly placed. 
>
>The seeds are properly placed.  Is it the case that FloodFill only
>fills over the background?  If so, no mention of this is made in the
>reference guide.

In using FloodFill there are three aspects to consider.  The first
is the borderline color, which defines the area to be filled.  The
second is the actual fill color which is allowed to be different
from the borderline color.  The third consideration is the pattern
of the fill (it is best first to test with SolidFill).  As to the
location of seeds, note that if the seed falls on the border, you
may not get a fill.  The other problem is that if your border is
broken (that is you eg cross it by a line) FloodFill will leak all
over the screen.  I'm using TP 5.0 myself, but (so far) I have not
come upon any instances where the fill system fails to work for
reasons other than failings in my own logic. 

Finally, here is an (on the fly) example of one sequence that fills
a circle
  SetColor (YourBorderColor);
  Circle (Your_x, Your_y, Your_r);
  SetFillStyle (SolidFill, YourFillColor);
  FloodFill (Your_x, Your_y, YourBorderColor);

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

2fluluck@kuhub.cc.ukans.edu (10/09/90)

In article <Sep.29.14.48.07.1990.26812@emerald.rutgers.edu>, clong@emerald.rutgers.edu (Chris Long) writes:
> Has anyone else had problems with TP5.5's FloodFill?  I do a
> 
  [stuff deleted]
> It draws the grid nicely and does the first set of fills, but the
> next set of fills does nothing.
> 
> -Chris

I've had a few problems with the FloodFill procedure.  It works fine as long
as you are using solid fills, but if you are doing fills with patterns, it
gets goofy.  This is due to the algorithm that Turbo uses (if there aren't any
changes in one direction in x number of pixels, it abandons that path).  This
can result in only part of the area being filled.

The way I solved this is to FloodFill the area with a solid pattern, then
FloodFill it again with the pattern or whatever you need.  This is dependant
upon the particular image being played with, so you may have to do several 
solid fills from different locations within the area in order for it to work.

Of course, if worst comes to worst, you could just write your own
FloodFill-type routine in Turbo using GetPixel and PutPixel.  That is how I 
originally did it, but it is simply too slow that way (at least for me).

		Steve Penrod
		University of Kansas