#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Limit MouseX & MouseY Movement

edited December 2017

I was wondering what the best way to limit mouse movement, for example if I put mouseX and mouseY on these pupils

``````ellipse(280,165,28,28); //Left Eye
ellipse(310,165,28,28); //Right Eye
fill(0);
ellipse(278,162,3,3);   //Left Pupil
ellipse(315,167,3,3);   //Right Pupil
``````

how would I limit movement to within the eyes?

Tagged:

`constrain()`

• Thanks, I see the params are n low and high, what would be the best way to set this to the ellipse of the left eye?

maybe set x&y as n, then set Left Eye to a variable and use that for both low and high?

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

void draw() {
background(0, 128, 0);
fill(255);
ellipse(280, 165, 28, 28); //Left Eye
ellipse(310, 165, 28, 28); //Right Eye
fill(0);
ellipse(278, 162, 3, 3);   //Left Pupil
ellipse(315, 167, 3, 3);   //Right Pupil

fill(255);
ellipse(100, 200, 50, 50);
PVector pvl = new PVector(mouseX-100, mouseY-200);
pvl.limit(20);
fill(0);
ellipse(100+pvl.x, 200+pvl.y, 10, 10);

fill(255);
ellipse(150, 200, 50, 50);
PVector pvr = new PVector(mouseX-150, mouseY-200);
pvr.limit(20);
fill(0);
ellipse(150+pvr.x, 200+pvr.y, 10, 10);

}
``````
• I really appreciate your quick responses

I just realized I am posting this in the wrong area, should be in p5.js questions not processing, sorry.. I've shared the work here.

• got it working with createVector, thanks!