I'm trying to implement a paint bucket tool in a Python program using Pygame, but I'm confused about how to effectively use greedy meshing or a binary array for this purpose. I've searched for clear explanations online, but I haven't found any resources that help me understand how to go about this. Can anyone provide some guidance on implementing this tool?
2 Answers
Could you share what you've made so far? Are you working on a 2D painting application? Do you already have a 2D array that represents your pixels? By the way, the algorithm you're looking for is typically called "bucket fill," which is different from greedy meshing.
A paint bucket tool is commonly implemented using a depth-first search (DFS) approach that fills connected "cells" in a graph, which in your case are pixels in a 2D array. Greedy meshing is usually more applicable in 3D voxel scenarios, so I’m assuming you're focusing on a 2D project? If that's the case, check out the traditional Flood Fill algorithm. Here's a link for reference: [Flood Fill](https://en.wikipedia.org/wiki/Flood_fill)
Yes, I am using Flood Fill, but it's slower than I need. This is strictly a 2D paint tool, and all inputs come from the keyboard.

I see! Thanks for the clarification. My current method is really slow, and I'm looking for ways to optimize it.