xxxxxxxxxx
51
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
}
let hasSensorPermission = !(DeviceOrientationEvent.requestPermission || DeviceMotionEvent.requestPermission);
function begPermission(){
if (DeviceOrientationEvent.requestPermission){
DeviceOrientationEvent.requestPermission()
.then(response => {
if (response == 'granted') {
if (DeviceMotionEvent.requestPermission){
DeviceMotionEvent.requestPermission()
.then(response => {
if (response == 'granted') {
hasSensorPermission = true;
}
})
.catch(alert)
}
}
})
.catch(alert)
}
}
function touchEnded() {
if (!hasSensorPermission){
begPermission();
}
}
function setup() {
createCanvas(800, 800);
textSize(16);
}
function draw() {
background("pink");
text("Touch screen to grant permission on mobile phone or tablet", 20, 20);
text(`Alpha: ${rotationX}` , 20, 52);
text(`Beta: ${rotationY}` , 20, 102);
text(`Gamma: ${rotationZ}`, 20, 152);
}