The formula for calculating the speed of the mouse’s horizontal motion is the absolute value of the difference between mouseX and pmouseX. The absolute value of a number is defined as that number without its sign:
- The absolute value of –2 is 2.
- The absolute value of 2 is 2.
- abs(mouseX - pmouseX)
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
void setup() {
size(200, 200);
background(255);
smooth();
}
void draw() {
stroke(0);
strokeWeight(abs(pmouseX - mouseX));
line(pmouseX, pmouseY, mouseX, mouseY);
}








