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.