sunjay / turtle

Create Animated Drawings in Rust
http://turtle.rs
Mozilla Public License 2.0
562 stars 53 forks source link

Flood Fill #61

Open sunjay opened 6 years ago

sunjay commented 6 years ago

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).

PaulDance commented 4 years ago

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

sunjay commented 4 years ago

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

PaulDance commented 4 years ago

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.

sunjay commented 4 years ago

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.