p5.js | Mouse | mouseY
Last Updated :
16 Apr, 2019
The mouseY variable in p5.js is used to store the current vertical position of the mouse, relative to (0, 0) of the canvas. If touch is used instead of mouse input, mouseX will hold the y value of the most recent touch point.
Syntax:
mouseY
Below programs illustrate the mouseY variable in p5.js:
Example 1: This example uses mouseY variable to display vertical position ofmouse.
function setup() {
createCanvas(1000, 400);
textSize(20);
}
function draw() {
background(200);
rect(height/2, mouseY, 30, 30);
text( "Position of mouseY relative to canvas is: "
+ mouseY, 30, 40);
}
|
Output:
Example 2: This example uses mouseY variable to display vertical position ofmouse.
function setup() {
createCanvas(1000, 400);
textSize(20);
}
function draw() {
background(200);
circle(mouseX, mouseY, 30);
text( "Position of mouseY relative to canvas is: "
+ mouseY, 30, 40);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/mouseY
Share your thoughts in the comments
Please Login to comment...