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 › map() and if(mousePressed)
Page Index Toggle Pages: 1
map() and if(mousePressed) (Read 257 times)
map() and if(mousePressed)
Nov 17th, 2008, 4:03am
 
If i remove the mousePressed condition, the arc and ellipse make 1 360 degree rotation.  With the mousePresed condition, the arc and the ellipse travel much further than 360 degrees, I cannot figure out why that would be.

I am new to processing and programming in general, so point out any indelicacies in the code.

float arcStop;
float theta;
float x,y;

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

 
}

void draw(){
 background(50);
 noFill();
 smooth();
 
 arc(200,200,100,100,0,arcStop);
 ellipse(x,y,10,10);
 
 if(mousePressed){
 arcStop=map(mouseX,0,width,0,TWO_PI);
 theta=TWO_PI+arcStop;
 x=50*cos(theta)+200;
 y=50*sin(theta)+200;
 }
}
Re: map() and if(mousePressed)
Reply #1 - Nov 17th, 2008, 8:33am
 
that's because a normal mouse move (not pressed) will end at the edges of your sketchs drawing area while a mouse drag will go on beyond that space.

you could check against the values if you need to:

if ( mousePressed && mouseX >= 0 && mouseX <= width ) {
 ...
}

F
Page Index Toggle Pages: 1