The formula for calculating the speed of the mouse\'s horizontal motion is the a
ID: 3708845 • Letter: T
Question
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. In Processing, you can get the absolute value of the number by placing it inside the abs () function, that is abs (-5) equals 5. The speed at which the mouse is moving is therefore float mouseSpeed abs (mouseX pmou sex); - Fill in the blank below and then try it out in Processing! stroke(e); Line(pmousex, pmouseY, mousex, mouseY)Explanation / Answer
The speed at which the mouse is moving is therefore:
- abs( mouseX - pmouseX )
The faster the user moves the mouse, the wider the drawn line.
Here by look up the strokeWeight( ) in the Processing reference.
In addition to mouseX and mouseY , you can also use pmouseX and pmouseY.
These two keywords stand for the previous mouse X and mouse Y locations, that is,
where the mouse was the last time we cycled through draw( ).
By connecting the previous mouse location to the current mouse location with a line each time through draw( ) ,
we are able to render a continuous line that follows the mouse.
void setup() {
size(200, 200); // Set the size of the window
background(255); // Draw a white background
}
void draw() {
stroke(0);
strokeWeight(abs(pmouseX - mouseX));
line(pmouseX, pmouseY, mouseX, mouseY);// Draw a line from previous mouse location to current mouse location.
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.