xxxxxxxxxx
// tilt and rotation for enabled devices
// on a desktop nothing will happen, but it wont break
// variables allow motion and ios to be detected.
// further code to detect a compass and tilt hardware on non-ios devices needed
let motion = false;
let ios = false;
// below code is essential for ios13 and above.
// A click is needed for the device to request permission
if (typeof DeviceMotionEvent.requestPermission === 'function') {
document.body.addEventListener('click', function() {
DeviceMotionEvent.requestPermission()
.then(function() {
console.log('DeviceMotionEvent enabled');
motion = true;
ios = true;
})
.catch(function(error) {
console.warn('DeviceMotionEvent not enabled', error);
})
})
} else {
// we are not on ios13 and above
// todo
// add detection for hardware for other devices
// if(got the hardware) {
// motion = true;
// }
}
function setup() {
createCanvas(windowWidth, windowHeight);
textSize(60);
}
function draw() {
background(0);
for(let i = 0;i<touches.length;i++)
{
fill(255);
ellipse(touches[i].x, touches[i].y, 50, 50);
fill(255, 0, 0);
//textMode(CENTER, CENTER);
//textSize(40);
text(touches[i].id, touches[i].x, touches[i].y);
}
}