diff --git a/website/canvas/event-propagators-with-device-gravity.html b/website/canvas/event-propagators-with-device-gravity.html index fd04998..d95bd23 100644 --- a/website/canvas/event-propagators-with-device-gravity.html +++ b/website/canvas/event-propagators-with-device-gravity.html @@ -34,6 +34,7 @@ + Hello World { + function onDeviceOrientation(e) { console.log(event); - // ropes.forEach(rope => { rope.gravity = { x: 0, y: 0} }) - }); + // ropes.forEach(rope => { rope.gravity = { x: 0, y: 0} }) + } + + async function enableGravity() { + if (DeviceOrientationEvent.requestPermission) { + const permission = await DeviceOrientationEvent.requestPermission(); + + if (permission === "granted") { + window.addEventListener("deviceorientation", onDeviceOrientation); + } else { + console.warn('Permission for device orientation rejected', permission) + } + } else { + window.addEventListener("deviceorientation", onDeviceOrientation); + } + }