p5.js turnAxis variable
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
// Define a variable that will hold // the background color var value = 0; function setup() { createCanvas(windowWidth, windowHeight); // Set the background as the variable background(value); } // Define the draw function function draw() { // Set the properties of text background(value); fill(0, 0, 255); textAlign(CENTER, CENTER); textSize(25); // Set the limit for value // When the value is greater than 10 if (value === 0) { text( "Device is Relaxed " , width / 2, height / 2); } else { text( "Device is moved in X- axis" , width / 2, height / 2); } } // Set the value depending on the turnAxis function deviceTurned() { if (turnAxis === 'X' ) { // Constrain the value so that // it can be used as the background // color value = constrain(value + 50, 0, 255) } } |
Output:
Reference:https://p5js.org/reference/#/p5/turnAxis
Please Login to comment...