home/ atoms/ processing-mouse-input

mouseX, mouseY and pmouseX, pmouseY give current and previous cursor positions for interaction

Processing provides built-in variables for mouse state. mouseX and mouseY update to the cursor’s current pixel position at the start of each draw() call. pmouseX and pmouseY hold the position from the previous frame. Drawing a line from (pmouseX,pmouseY) to (mouseX,mouseY) creates a painting tool that connects frames. mousePressed is a boolean (true while a button is held). mouseButton identifies LEFT, RIGHT, or CENTER. The event functions mousePressed(), mouseReleased(), mouseDragged(), and mouseMoved() run once per event independently of draw().

Examples

void draw() { if (mousePressed) { line(pmouseX, pmouseY, mouseX, mouseY); } }

Assessment

Implement a simple paint program where line thickness is proportional to mouse speed (use dist(mouseX,mouseY,pmouseX,pmouseY)); test boundary conditions when the mouse is stationary.

“mouseX and mouseY values can control translation, rotation, and scale by using them as parameters in the transformation functions”
corpus · processing-handbook-no-login-mirror-pdf-reas-and-fry · chunk 48