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.
IndexProgramming Questions & HelpSyntax Questions › How to remove a picture after drawing it
Page Index Toggle Pages: 1
How to remove a picture after drawing it? (Read 678 times)
How to remove a picture after drawing it?
Mar 21st, 2009, 1:51am
 
I'm brand spanking new to Processing, but not to programming. I'm going through the examples and can't figure out a couple of things about drawing images.

1) how do I remove it after I draw it?

2) if I want to draw shapes above the image, do I need to make the image be a background?

Here's the code I'm playing with:


PImage pica;  // Declare variable "pica" of type PImage


void setup() {
 size(400, 400);
 background(192, 64, 0);
 pica = loadImage("jelly.jpg");
}


// the draw() function runs repeatedly.
void draw() {
 
 stroke(255);
 line(150, 25, mouseX, mouseY);

 if (mouseX > 100) {
   image(pica, 0, 0);
 }
 
 else {
    // how to delete the image?

  }

}


In the above example, I'd like to remove the image from the canvas when the mouseX >= 100. And if possible, I'd like to do so without affecting whatever lines have been drawn on the canvas. Currently it removes all the lines when the image is replaced.

Thanks for any help.

Re: How to remove a picture after drawing it?
Reply #1 - Mar 21st, 2009, 6:53am
 
You would probably want to use PGraphics.

http://processing.org/reference/PGraphics.html

That will let you draw your lines to it.

Then, in the draw() method, use background(somecolor); to clear, then image() the picture and image() the PGraphics with the lines drawn.

If you do not use background() on the PGraphics, the lines will stay intact.
Re: How to remove a picture after drawing it?
Reply #2 - Mar 21st, 2009, 9:15am
 
As said, in Processing, all drawings persist on screen, the only way to remove them is to draw over them.
Actually, the most common idiom is to erase the full sketch surface (usually with background() or by drawing an image over it) and redraw everything on each draw() call.
It supposes, if drawings come from user interaction (like a paint program), that you record everything they do. Either the coordinates of actions, or as said you draw in a secondary graphics and display it on screen, adding any secondary graphics (eg. controls) over it.
Page Index Toggle Pages: 1