Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptp5.js | Mouse | winmouseX

p5.js | Mouse | winmouseX

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

Syntax:

mouseX

Below programs illustrate the mouseX variable in p5.js:

Example 1: This example uses winmouseX 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 position of winmouseX
    text("Position of winmouseX is " 
        + winMouseX, 30, 40);
}


Output:

Example 2: This example uses winmouseX variable to display some content if condition is satisfied.




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


Output:

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

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

Recent Comments