Wednesday, July 3, 2024
HomeLanguagesJavascriptp5.js | Mouse | pmouseX

p5.js | Mouse | pmouseX

The pmouseX variable in p5.js is used to store the horizontal position of the mouse cursor in the frame previous to the currently active frame, relative to the origin of the canvas.

Syntax:

mouseX

Below programs illustrate the pmouseX variable in p5.js:

Example 1: This example uses pmouseX 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(pmouseX, mouseX, pmouseX%100);
}


Output:

Example 2: This example uses pmouseX 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 pmouseX is "
        + pmouseX, 30, 40);
}


Output:

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

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!

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments