turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Flood Fill

Open sunjay opened this issue 8 years ago • 4 comments

The LOGO programming language has a fill command which essentially performs a flood fill starting at the turtle's current position.

Filling in Solid Shapes

Now that we know how to move the turtle without drawing a line, we can make the turtle go inside a shape that it has drawn. Then we can fill the entire shape with a single color, using the FILL command.

You can think of the FILL command as pouring out a bucket of special paint and flooding the area under the turtle. The paint is special in that it can't flow over pixels that have a different color than the pixel that the turtle is over.

To add this to turtle, add a public fill() method that sends an appropriate drawing command and performs the necessary algorithm to determine the fill. Add the filled area to the drawings as a polygon or using a better representation.

Make sure the fill method has some examples in the examples directory along with some documentation and some tests (if testing would be useful here).

sunjay avatar Jan 16 '18 07:01 sunjay

Would this still be useful considering the begin_fill and end_fill methods?

PaulDance avatar Oct 09 '20 18:10 PaulDance

Yes. Those methods do not perform a flood fill. They fill the path that the turtle is currently drawing.

sunjay avatar Oct 09 '20 18:10 sunjay

Then shouldn't we name this flood_fill instead? I just think it would be a bit confusing to have fill, begin_fill, and end_fill, like two ways of achieving the same result, which is not the case.

PaulDance avatar Oct 09 '20 18:10 PaulDance

Sure, yeah. That name makes sense too. The fill name was mainly to refer back to the corresponding Logo command. Adherence to that is not mandatory.

sunjay avatar Oct 09 '20 18:10 sunjay