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
Erase tool (Read 1355 times)
Erase tool
Jun 10th, 2008, 1:55am
 
Hi!
I'm doing a basic drawing program. I want to implement an eraser tool.
The problem is that when I Stroke(0,0,0,0) nothing is drawn, I guess this happens  because the fusionmode in processing must me addictive all the time.

I draw into a Pgraphics.
Re: Erase tool
Reply #1 - Jun 10th, 2008, 7:30am
 
Sure, Processing is addictive! Wink
You set stroke (lower case) with four parameters at 0.
The first one is the alpha value: 0 = full transparent, so you won't see anything drawn... Omit it to have it at 255 by default.
BTW, 0 is black. If you draw on a black board, it is indeed an eraser, but most drawing programs use white as background: 255, 255, 255.
Re: Erase tool
Reply #2 - Jun 10th, 2008, 10:13am
 
The problem is that I'm not drawing on to a black background. I am drawing on a transparent layer (PGraphics) on top of a photograph http://wiki.medialab-prado.es/images/9/99/Firstframe.png

Thnak you
Re: Erase tool
Reply #3 - Jun 10th, 2008, 12:41pm
 
Ah, I understand better. Since I am new to Processing, I might be overlooking something obvious, but I don't see how to use drawing primitives to restore the pristine state of a part of a transparent PGraphic.
A possible way is to manually overwrite the pixels around the erasing position with the default value (0x0).
Re: Erase tool
Reply #4 - Jun 10th, 2008, 12:56pm
 
I guess it would possible to make a delete tool by accessing to pixels[] and setting values to 0x0. But there must be a simpler way, A way in which the drawing operations (line, polygon...) performed on the PGraphics overwrite the alpha channel instead of adding to it.

Help,help!
Re: Erase tool
Reply #5 - Mar 21st, 2009, 8:40am
 
Here I am digging up old topics!  I would really like an answer to this problem.  How do you "erase" from a buffer.
Re: Erase tool
Reply #6 - Mar 21st, 2009, 9:38am
 
Even with a bit more knowledge of Processing, the answer is basically the same...
I experimented a bit with mask(): problem, it doesn't work with a JAVA2D graphics, and on a P2D graphics, it alters the transparent background.
I give here my experimentation, it might be OK if the restrictions doesn't affect you.
Code:
void setup()
{
size(500, 500);
background(#9900CC);
PGraphics g = createGraphics(500, 500, P2D);
g.beginDraw();
// g.noStroke();
for (int i = 0; i < 50; i++)
{
g.fill(random(100, 200));
g.rect(random(10, 300), random(10, 300), random(100, 200), random(100, 200));
}
g.fill(0, 0); // Transparent Black
// Doesn't work!
g.rect(100, 100, 300, 300);
g.endDraw();

PGraphics msk = createGraphics(500, 500, JAVA2D);
msk.beginDraw();
msk.background(255);
msk.fill(0);
msk.rect(100, 100, 300, 300);
msk.endDraw();

g.mask(msk);

image(g, 0, 0);
}
Page Index Toggle Pages: 1