p5.js turnAxis variable
Last Updated :
12 May, 2021
The turnAxis variable is used to store the axis triggered by the deviceTurned() method. This takes place when a mobile device is rotated in any of the X, Y or Z axis. This variable is only defined within the scope of the deviceTurned() function.
Syntax:
turnAxis
The below example demonstrates the turnAxis variable in p5.js:
Example:
Javascript
var value = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
background(value);
}
function draw() {
background(value);
fill(0, 0, 255);
textAlign(CENTER, CENTER);
textSize(25);
if (value === 0) {
text( "Device is Relaxed " ,
width / 2, height / 2);
} else {
text( "Device is moved in X- axis" ,
width / 2, height / 2);
}
}
function deviceTurned() {
if (turnAxis === 'X' ) {
value = constrain(value + 50, 0, 255)
}
}
|
Output:
Reference:https://p5js.org/reference/#/p5/turnAxis
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...