So, I came across this tutorial, http://processing.org/learning/topics/continuouslines.html and now I know how to scrible. I wanted to implement an added functionality, where if we encircle a scrible, the circled section gets colored. Like flood fill. That is, if I scrible around a car's image, on completing the scrible around the car's border, the car turns red colored. Please help with a code snippet if possible. If you think this question should have been asked under "Programming questions", I shall do so. Thanks a lot.
Well, if you assume that you only want to enclose one shape at a time, you could just keep track of the lines drawn (as an ArrayList of points, say), and then check each new line drawn to see if it overlaps with any of the previous lines (there's a formula for that, I'm sure(?)) - once you find a pair of lines that cross each other, you know that the lines between those two form a shape, which you can then color in with a triangle strip...
I might have to modify it a bit, because it would be great if the car gets colored as soon as I complete the border. For example, if I draw a square type shape, the moment I finish drawing, the point of starting co-incides with the end-point, the shape gets colored. But this is a very helpful start. Thanks again.
Chrisir: hello, as you remember, I asked two questions lately: 1- this floodfill one, 2- undo the drawing one.. Finally, I was trying to work on them, and merge both the codes to create something where one can choose an image, then draw anything over it, use backspace to undo (lines, and if possible the colored patch too), and if an enclosed shape is created, then on keypress+click=colors that section. I hope I am able to convey things properly, think of MS paint's related features.
Basically, currently the code is doing things partially..when there's no image in the background, the color feature works, but the undo does not.. I was trying to play with the Buch2 file's draw() function. When image is added, then the flood feature does not work, etc etc. I guess not much work is needed to get the expected result, but I might be missing something. Can you please help me on that? Thanks so much!!!
There's an issue though, that when we undo after there's a colored patch. So undo only undoes the lines, and not the patch, this causes a weird spread all over the patch. This is probably because pixels of patch aren't saved in the ArrayList for the undo. Hmmm... Thanks again!