Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flood fill paint function #2683

Merged
merged 5 commits into from
Sep 30, 2024
Merged

flood fill paint function #2683

merged 5 commits into from
Sep 30, 2024

Conversation

anescient
Copy link
Contributor

@anescient anescient commented Sep 13, 2024

This is an implementation of Paul Heckbert's flood fill, providing the functionality of the QBasic PAINT method. This fills a contiguous area of solid color starting from a seed point.

All languages are supported, but not all languages are tested.

There's a closed/wishlist for this: #2022

Edit: Actually this isn't quite like QB's PAINT. Continued below.

@anescient
Copy link
Contributor Author

I was able to generate some torture tests that hit the stack limit around 3000, so I've changed the stack size to 4000. I'm not sure how to generate an absolute worst case, so I'm not sure how large is too large.

@sinsinpub
Copy link

just a random thought since qb mentioned, 2nd param bordercolor also frequently used and worth to be implemented?
image

@anescient
Copy link
Contributor Author

just a random thought since qb mentioned, 2nd param bordercolor also frequently used and worth to be implemented?

Definitely worth it but might need another implementation; I think this painter depends on stopping at its own color.

@anescient
Copy link
Contributor Author

I went back to check the behavior of QB paint when it's given a border color, and it turns out there's always a border color that just defaults to the paint color. For reference:

qbpaints1

I'm thinking tic paint should replicate this behavior if a border color is provided, but then unlike QB paint if no border color is given it should fill whatever contiguous space starts at the seed point, like I've implemented so far.

@anescient
Copy link
Contributor Author

I'm finding QB paint is silly and shouldn't be replicated exactly. When a boundary color is given it's hard to predict whether the paint will leak through its own color:

qbpaints2

Rather than using QB as reference the behavior I'm going to pursue is: if a border color is given then paint to within the border color or the paint color itself, and as before, when no border color is given then effectively every color is border except the color at the seed point.

@anescient
Copy link
Contributor Author

I found a worse worst case for memory usage which suggested the stack limit should be about 10,000 to be safe, so I've replaced the stack with a much smaller queue.

@anescient anescient marked this pull request as ready for review September 16, 2024 16:52
@nesbox nesbox merged commit e63ab8d into nesbox:main Sep 30, 2024
12 checks passed
@anescient anescient deleted the paintfn branch September 30, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants