We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
paint() (Read 794 times)
paint()
Oct 7th, 2007, 5:48am
 
Is there some paint(x,y,color) or fill(x,y,color) function
to put color at a point and fill the whole region ?
(as for example in the Microsoft Paint software) ?
Re: paint()
Reply #1 - Oct 8th, 2007, 3:53am
 
Nope, it's not built in to Processing, though depending on Ben's feelings, it might be the kind of feature that he might consider once Processing is out of beta and he starts thinking about new features - it is a pretty primitive operation, so it could be useful as part of the core, though it is tough to imagine what it should do in 3D, and it won't play well with OpenGL.

However, you can certainly implement flood-fill yourself for now: http://www.codecodex.com/wiki/index.php?title=Implementing_the_flood_fill_algorithm explains how to do it in pure Java, though to use it in Processing you'll need to access the pixels[] array directly instead of using the methods they use there; if you don't know much about pixels[], search the forums a bit to see how it is used.  If you get it working, please let us know, I'm sure a lot of people would find the code pretty useful.  If you need help, just ask.
Re: paint()
Reply #2 - Oct 8th, 2007, 12:40pm
 
Thanks for the info and reference. I will look more into that when I have time.

On a first quick look, it's strange how simple and clean is the pseudocode, compare to the Java implementation.

I guess a floodfill function has to use low level instructions to be efficient, so functions like get(), set(), point() won't be enough.

Looking into the Reference, I find those relevant comments:

Getting the color of a single pixel with get(x, y) is easy, but not as fast as grabbing the data directly from pixels[]. The equivalent statement to "get(x, y)" using pixels[] is "pixels[y*width+x]".

Setting the color of a single pixel with set(x, y) is easy, but not as fast as putting the data directly into pixels[]. The equivalent statement to "set(x, y, #000000)" using pixels[] is "pixels[y*width+x] = #000000".

The (BETA) version of Processing requires calling loadPixels() to load the display window data into the pixels[] array before getting the values and calling updatePixels() to update the window.
Page Index Toggle Pages: 1