0

I was trying to create a function that can fill an area like the bucket/fill option on the paint application.

Here is another example of what I'm trying to create (from skribbl.io).enter image description here

I already have code that draws and create shapes and everything, here is the code snippet in case you wanted to test it, it's messy and not organized because I didn't finish creating the project yet, therefore if you know how to create a function to fill a closed area like shown in the image that would be appreciated.

Codepen: https://codepen.io/karimx32/pen/dyZewPE
Live example of what I need (video): https://ultrax-yt.com/assets/example.mov

so what I need is to create something like:

function fill() {
    // code that will fill the area when I click on it
}
UltraX
  • 379
  • 1
  • 5
  • [Flood fill](https://en.wikipedia.org/wiki/Flood_fill) is what you need, it's not a trivial task. – Teemu Feb 22 '22 at 13:22
  • @Teemu well ty for telling me it's the correct name, but that didn't answer my question. Thank you tho! – UltraX Feb 22 '22 at 13:32
  • What is your question then? SO is not a free coding service. From the linked wiki article you can find multiple pseudo-code examples of the algorithms, try to implement one of those, and if you'll get stuck, then ask a question about the issues you're facing. – Teemu Feb 22 '22 at 13:36
  • I already know how to do it for geometric shapes, like if its a square as an example, I know how to fill it but this here could be in any shape, so I just wonder how to do it – UltraX Feb 22 '22 at 13:38
  • So, you didn't even take a look at the linked wiki ... – Teemu Feb 22 '22 at 13:39
  • i did look, but i don't get how can I do it using HTML5 Canvas – UltraX Feb 22 '22 at 13:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/242268/discussion-between-ultrax-and-teemu). – UltraX Feb 22 '22 at 14:15

0 Answers0