Skip to content

Instantly share code, notes, and snippets.

@limzykenneth
Created May 8, 2020 13:43
Show Gist options
  • Save limzykenneth/ff898d23c44b86824c986d209e8a32a7 to your computer and use it in GitHub Desktop.
Save limzykenneth/ff898d23c44b86824c986d209e8a32a7 to your computer and use it in GitHub Desktop.
p5.js Example rotationX/Y/Z with Permission
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