Open In App

p5.js | Mouse | winmouseY

Last Updated : 17 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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.




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);
}


Output:

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




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);
  }
}


Output:

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads