- numpy from js import addGravityListener from pyodide import create_proxy import numpy as np span = document.querySelector("span") def callback(x, y, z): span.innerText = orientation(x, y, z) def orientation(x, y, z): gravity = np.array([x, y, z]) v = list(np.round(gravity / np.linalg.norm(gravity)).astype(int)) if v == [ 1, 0, 0]: return "Horizontal counterclockwise" if v == [-1, 0, 0]: return "Horizontal clockwise" if v == [ 0, 1, 0]: return "Vertical upright" if v == [ 0, -1, 0]: return "Vertical upside down" if v == [ 0, 0, 1]: return "Screen up" if v == [ 0, 0, -1]: return "Screen down" return "Tilted" addGravityListener(create_proxy(callback))