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
spray drop! (Read 1057 times)
spray drop!
Aug 7th, 2009, 6:37am
 
hey! im trying to make a little kind of graffity program! i got the strokes and i even got a pretty basic drop class but i only want to run its method when the mouse is Pressed in the same mouseX and mouseY for more than 30 frames. in other words, i want to run the method of the drop when the mouse is pressed but not moving.

if the code is needed say something! thanks in advanced!
Re: spray drop!
Reply #1 - Aug 7th, 2009, 8:01am
 
Are you saying you want help with the code?

It should be easy enough to use a variable to count the number of frames elapsed and to do something only if it is greater than 30; and just reset it to zero on mouseRelease, mousePress and mouseDragged.  Though you might find you want to allow slight movement and still invoke the drop method, in which case you could just store xy coords on mousePressed, calculate the distance from this each frame and reset to zero if it goes over a certain threshold...
Re: spray drop!
Reply #2 - Aug 7th, 2009, 8:02am
 
Something like this?

Code:

boolean grabFrame = true;
int grabbed_frame;
color bg_color = color(0);

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

void draw(){
 if(mousePressed && (mouseX == pmouseX) && (mouseY == pmouseY)){
   if(grabFrame){
     grabbed_frame = frameCount;
     grabFrame = false;
   }
   
   if(frameCount - grabbed_frame > 30){
     bg_color = color(255);
   } else {
     bg_color = color(0);
   }
 }
 background(bg_color);
}

void mouseReleased(){
 bg_color = color(0);
 grabbed_frame = 0;
 grabFrame = true;
}

Re: spray drop!
Reply #3 - Aug 7th, 2009, 9:28am
 
I tested that and it has a slight bug:

If you just happen to move the cursor over the pmouseX and pmouseY position whilst dragging it switches state: perhaps not desired.  I had something like this in mind:

Code:
boolean mouseDown = false;
int frameCount = 0;
color bg_color = color(0);

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

void draw(){

if(mouseDown) {  
 frameCount++;
}
 
   if(frameCount> 30){
     bg_color = color(255);
   } else {
     bg_color = color(0);
   }

 background(bg_color);
}

void mousePressed() {
 frameCount = 0;
 mouseDown = true;
}

void mouseDragged() {
 frameCount = 0;
}

void mouseReleased(){
 frameCount = 0;
 mouseDown = false;
}


Note that this might not achieve what was intended either, since dragging switches the state back to 'off', perhaps not desired for a painting program where once a flow of drops has been established you might then want to allow the user to paint a stroke...
Re: spray drop!
Reply #4 - Aug 7th, 2009, 9:57am
 
You know, I never actually knew you could alter the value of frameCount. I always assumed it was a constant that couldn't be altered. Nice job, I like yours better.  Smiley
Re: spray drop!
Reply #5 - Aug 7th, 2009, 10:19am
 
thanks guys! didn't know i could reset the frameRate(); it was a great help  Cheesy
Re: spray drop!
Reply #6 - Aug 7th, 2009, 11:11am
 
NoChinDeluxe wrote on Aug 7th, 2009, 9:57am:
You know, I never actually knew you could alter the value of frameCount. I always assumed it was a constant that couldn't be altered. Nice job, I like yours better.  Smiley


Nor did I! Embarrassed

I just unwittingly used a variable name that matches a Processing built-in variable...  Guess I was just lucky enough that my variable got local scope and didn't clash.

So strictly speaking you should probably use a different variable name Wink
Re: spray drop!
Reply #7 - Aug 8th, 2009, 9:05am
 
blindfish wrote on Aug 7th, 2009, 11:11am:
Nor did I! Embarrassed

I just unwittingly used a variable name that matches a Processing built-in variable...  Guess I was just lucky enough that my variable got local scope and didn't clash.

So strictly speaking you should probably use a different variable name Wink


HAHAHAHAHA. Classic.  Cheesy
Page Index Toggle Pages: 1