p5.js | Mouse | mouseIsPressed
The mouseIsPressed system variable in p5.js is used to store the boolean value. If mouse is pressed then it stores True otherwise store False.
Syntax:
mouseIsPressed
Below programs illustrate the mouseIsPressed variable in p5.js:
Example 1: This example uses mouseIsPressed variable to check mouse is press or not.
function setup() {
createCanvas(500, 250);
textSize(30);
}
function draw() {
background( 'green' );
fill( 'white' );
if (mouseIsPressed) {
text( "Mouse is Pressed" , 120, 100);
}
else {
text( "Mouse is Released" , 120, 100);
}
}
|
Output:
Example 2:
function setup() {
createCanvas(300, 150);
}
function draw() {
background( 'green' );
fill( 'white' );
if (mouseIsPressed) {
ellipse(50, 50, 50, 50);
}
else {
rect(25, 25, 50, 50);
}
}
|
Output:
Reference: https://p5js.org/reference/#/p5/mouseIsPressed
Last Updated :
16 Apr, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...