Loading...
Logo
Processing Forum

How to clear the screen on mouse click

Answered
  • Need more info
  • Answered
  • Working on it
in Programming Questions  •  3 years ago  
Hi sorry to ask such an elementary question but I am new to processing and really need help. Suppose I run this code this in Processing:
void setup ()
{
size (400, 400);
background (125);
stroke (1);
}
void draw ()
{
// pmouseX, pmouseY: previous pointer coordinates
// mouseX, mouseY: current pointer coordinates
line (pmouseX, pmouseY, mouseX, mouseY);
}

It will use the variables to draw a line that follows the movement of the pointer around the program window.  I need to modify the code so that Processing clears the screen whenever I click the mouse button. Any advice would be greatly appreciated, Thank you.

[Moderator's note: I renamed the title from "Question need help asap" which isn't informative at all on the nature of the question... Also marked the thread as answered, even if very few people do it actually...]

Replies(8)

Check the docs on "mouseReleased()" - should get you there

kb, http://www.riftgame.com/
Anybody else? Thanks kb but I cant seem to find docs, or make sense of mouseReleased when I google it.
all commands can be found in the reference http://processing.org/reference/

so mouseReleased would be http://processing.org/reference/mouseReleased_.html
there youll find your answer
And don't forget that you can highlight a keyword in Processing and hit Ctrl + Shift + F to be taken to the (usually) relevant Reference entry.
ah didnt know about the shortcut... you can also highlight it and just use rightclick and "find in reference"
Thanks to everyone for leading me to the references, however like I said I just started using Processing a couple of weeks ago, I cannot really make much sense of it. So if anyone can give me a tip or a pseudo example of this problem please do, Thanks!
mouseReleased() is called whenever a mouse button is released (surprisingly enough) so you can just put a background() call in it to clear the screen. Add something like this to your code after the end of your draw() block should work:
                
Copy code
  1. void mouseReleased() {
  2. background(125);
  3. }

Hope that helps. 

Thanks so much velvet!