Saturday, November 15, 2025
HomeLanguagesJavascriptp5.js | Mouse | pmouseY

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.




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


Output:

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




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


Output:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6890 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS