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 › void mousepressed()
Page Index Toggle Pages: 1
void mousepressed() (Read 464 times)
void mousepressed()
Nov 30th, 2008, 12:45pm
 
does any1 know how i can stop the rain by using a mousepressed function. the one i have done below doesnt seem to work. any suggestions????????

int numRains=100;

Rain [] rn = new Rain [numRains]; //arrange an array of droplets
 
void setup ()
{
 size (600,600);
 smooth ();
 noStroke ();
 
   for (int i=0; i<rn.length; i++)   {
   rn [i]= new Rain (random(width),10,random(width/200),random(1,width/40));
 }
}
void draw ()
{
 fill (0,15);
 background(0);
 for (int i=0; i<rn.length; i++){
   fill (255);
   rn[i].move ();
   rn[i].display ();
 }
}
class Rain
{
 float x,y;
 float diameter;
 float speed;
 int direction=1;  

 Rain (float xpos, float ypos, float dia, float sp)
 {
   x=xpos;
   y=ypos;
   diameter=dia;
   speed=sp;
 }

 void move () {

   y +=(speed * direction);
   if ((y>(height-diameter/2)) || (y<diameter/2)){
     y=0;
     /*
//this is good but only when the mouse is held down!
     if (mousePressed){
      y=height;
      }
      */
   }
 }

 void display() // draws the spot to the display
 {
   for (int i=0; i<15; i++){
     pushMatrix();
     translate (x,y+(i*2.5));  
     fill(25*i);
     ellipse (0,0,diameter,diameter);
     popMatrix();
   }
 }
//this is the bit that doesnt work!
 void mousePressed(){
   y +=(speed * direction);

   if ((y>(height-diameter/2)) || (y<diameter/2)){
     y=height;
   }
 }
}

Re: void mousepressed()
Reply #1 - Nov 30th, 2008, 3:06pm
 
void draw() {  
 if (IS_RUNNING) {
   ....do something....
 }
}

void mouspressed() {
IS_RUNNING = false;
}
Re: void mousepressed()
Reply #2 - Nov 30th, 2008, 3:25pm
 
thankyou however this process stops the rain entirely, i was hoping to be able to achieve a gradual stop as is possible by using
if (mousePressed){
y=height;
}
the problem is that you have to hold the mouse for this to work so is it possible to use this somehow in a mousepressed function?
Re: void mousepressed()
Reply #3 - Nov 30th, 2008, 7:04pm
 
try something like that

draw() {
 theValue *= 0.95
}

void mousepressed() {
theValue = 10;
}
Page Index Toggle Pages: 1