p5.js | Mouse | pmouseY

The pmouseY variable in p5.js is used to store the vertical position of the mouse cursor in the frame previous to the current active frame, relative to the origin of the canvas.

Syntax:

pmouseY

Below programs illustrate the pmouseY variable in p5.js:



Example 1: This example uses pmouseY variable to draw mouse pointer as circle.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Create canvas
    createCanvas(1000, 400);
}
   
function draw() {
      
    // Set the background color
    background(244, 248, 252);
      
    // Fill color relative pmouseX,
    // pmouseY and mouseY
    fill(pmouseX%255, pmouseY%255, mouseY%255);
      
    // Draw circle 
    circle(mouseX, pmouseY, pmouseX%100);
}

chevron_right


Output:

Example 2: This example uses pmouseY variable to display the position of mouse pointer.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
      
    // Create canvas
    createCanvas(1000, 400);
      
    // Set font size
    textSize(20);
}
   
function draw() {
      
    // Set background color
    background(200);
      
    // Display result
    text("Position of pmouseY is "
        + pmouseY, 30, 40);
}

chevron_right


Output:

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



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.




Article Tags :

Be the First to upvote.


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