p5.js | Mouse | winmouseY

The winmouseY variable in p5.js is used to store the current vertical position of the mouse, relative to (0, 0) of the window.

Syntax:

winmouseY

Below programs illustrate the winmouseY variable in p5.js:



Example 1: This example uses winmouseY variable to display its position.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Create canvas of given size
    createCanvas(1000, 400);
      
    // Set the text size
    textSize(20); 
}
   
function draw() {
      
    // Set the background color
    background(200);
      
    // Create rectangle
    rect(winMouseX, winMouseY, 10, 10);
      
    // Display winMouseY position
    text("Position of winMouseY is "
        + winMouseY, 30, 40);
}

chevron_right


Output:

Example 2: This example uses winmouseY variable to display content.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Create canvas of given size
    createCanvas(500, 500);
      
    // Set the text size
    textSize(20); 
}
   
function draw() {
      
    // Set background color
    background(200);
      
    // Create circle
    circle(winMouseX, winMouseY, winMouseX-winMouseY);
      
    // Create line
    line(0, 0, windowWidth, windowHeight);
      
    // Check condition and display content
    if( winMouseX != winMouseY ) {
        text("You Lose", 12, 34);
  }
}

chevron_right


Output:

Reference: https://p5js.org/reference/#/p5/dwinmouseY



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : ManasChhabra2



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.