p5.js | Mouse | winmouseX
The winmouseX variable in p5.js is used to store the current horizontal position of the mouse, relative to (0, 0) of the window.
Syntax:
mouseX
Below programs illustrate the mouseX variable in p5.js:
Example 1: This example uses winmouseX variable to display its position.
function setup() {
createCanvas(1000, 400);
textSize(20);
}
function draw() {
background(200);
rect(winMouseX, winMouseY, 10, 10);
text( "Position of winmouseX is "
+ winMouseX, 30, 40);
}
|
Output:
Example 2: This example uses winmouseX variable to display some content if condition is satisfied.
function setup() {
createCanvas(500, 500);
textSize(20);
}
function draw() {
background(200);
circle(winMouseX, winMouseY, winMouseX-winMouseY);
line(0, 0, windowWidth, windowHeight);
if (winMouseX!=winMouseY ) {
text( "You Lose" , 12, 34);
}
}
|
Output:
Reference: https://p5js.org/reference/#/p5/dwinmouseX
Last Updated :
16 Apr, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...