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 › Mouse Input not working
Page Index Toggle Pages: 1
Mouse Input not working (Read 774 times)
Mouse Input not working
Aug 25th, 2009, 5:57pm
 
So here is my Code:

void randomline(){
 for (int i=0; i< 75; i++) {
   mouseReleased();
 }
}
void mouseReleased(){
 smooth();
 line(miceX, miceY, random(800), random(70));
}
void MousePressed(){
 miceX= mouseX;
 miceY = mouseY;
}



When I call all my functions together in draw, I can't figure out how to do the following:
Not draw until something is clicked
only draw once, instead of continually drawing.

Right now it just wants to draw from the corner, which happens to be where the play button is Smiley (I checked)
I'm thinking I need some sort of if/then structure, but where?  How do I stop the corner problem?
Re: Mouse Input not working
Reply #1 - Aug 26th, 2009, 5:20am
 
Well, for one you have a capital M in your mousePressed() method, which would cause it not to be called upon mouse press ...
Re: Mouse Input not working
Reply #2 - Aug 26th, 2009, 5:28am
 
I assume you wanted your sketch to do something like this:

Code:

void setup(){
 size(400,400);
 background(255);
}

void draw(){
 
}

void randomline(){
 stroke(0);
 smooth();
 line(mouseX, mouseY, random(width), random(height));
}

void mouseReleased(){
 randomline();
}


Notice that you were kind of doing things backwards. You want to create a custom method called randomline() which handles your drawing. All it does is draw a line from the current mouse position to a random spot somewhere on the screen. Then you want to call this method every time the mouse is clicked. So in the mouseReleased() function, which is a standard Processing function, you simply call your line drawing function to draw a line once every time the mouse is clicked. Is this what you were looking for?
Re: Mouse Input not working
Reply #3 - Aug 27th, 2009, 9:04pm
 
Yup, I left out the beginning parts of the call, because there are also font calls that are correct.  That part is kind of long, and boring, and working.

In the long term I am trying to figure out how to make the lines come out of concentric circles at random, as if it were a cracked window, when the mouse is clicked.

But first I better figure out how to get them come out normally.  Then I'll make an interation that does circles. with lines in them (hopefully)

It's a process.
Page Index Toggle Pages: 1