Created
May 8, 2020 13:43
-
-
Save limzykenneth/ff898d23c44b86824c986d209e8a32a7 to your computer and use it in GitHub Desktop.
p5.js Example rotationX/Y/Z with Permission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let canvas; | |
function setup() { | |
canvas = createCanvas(400, 400); | |
canvas.mouseClicked(function(){ | |
// Detect if DeviceOrientationEvent.requestPermission is implemented | |
if (typeof DeviceOrientationEvent.requestPermission === "function"){ | |
// If it is go ahead and call it. It returns a promise. | |
DeviceOrientationEvent.requestPermission().then(permissionState => { | |
if(permissionState === "granted"){ | |
console.log("Permission granted"); | |
}else if(permissionState === "denied"){ | |
console.log("Permission denied"); | |
} | |
}).catch(console.error); | |
}else{ | |
// Permission is not required | |
} | |
}); | |
} | |
function draw() { | |
background(220); | |
textSize(30); | |
text("Rotation X: " + rotationX, 10, 40); | |
text("Rotation Y: " + rotationY, 10, 80); | |
text("Rotation Z: " + rotationZ, 10, 120); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment