p5.js | Mouse | pmouseX
Last Updated :
16 Apr, 2019
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() {
createCanvas(1000, 400);
}
function draw() {
background(244, 248, 252);
fill(pmouseX%255, pmouseY%255, mouseY%255);
circle(pmouseX, mouseX, pmouseX%100);
}
|
Output:
Example 2: This example uses pmouseX variable to display the position of mouse pointer.
function setup() {
createCanvas(1000, 400);
textSize(20);
}
function draw() {
background(200);
text( "Position of pmouseX is "
+ pmouseX, 30, 40);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/pmouseX
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...