private updateTilt()

in sim/visuals/microbit.ts [869:919]


        private updateTilt() {
            const state = this.board;
            if (!state || !state.accelerometerState.accelerometer.isActive) return;

            const acc = state.accelerometerState.accelerometer;
            const x = acc.getX();
            const y = -acc.getY();
            const z = acc.getZ();
            const af = 8 / 1023;
            const s = 1 - Math.min(0.1, Math.pow(Math.max(Math.abs(x), Math.abs(y)) / 1023, 2) / 35);

            acc.updateEnvironmentGlobals();

            // fix top parent and apply style to it
            const el = this.findParentElement();
            el.style.transform = `perspective(30em) rotateX(${y * af}deg) rotateY(${x * af}deg) scale(${s}, ${s})`
            el.style.perspectiveOrigin = "50% 50% 50%";
            el.style.perspective = "30em";

            // don't display acc data when AB is on, v2 is on or soundLevel is on
            if (state.buttonPairState.usesButtonAB
                || this.v2Circle
                || this.soundLevel) {
                if (this.accTextX) this.accTextX.textContent = "";
                if (this.accTextY) this.accTextY.textContent = "";
                if (this.accTextZ) this.accTextZ.textContent = "";
            } else {
                // update text
                if (acc.flags & AccelerometerFlag.X) {
                    if (!this.accTextX) {
                        this.accTextX = svg.child(this.g, "text", { x: 365, y: 260, class: "sim-text" }) as SVGTextElement;
                        this.accTextX.textContent = "";
                    }
                    this.accTextX.textContent = `ax:${x}`;
                }
                if (acc.flags & AccelerometerFlag.Y) {
                    if (!this.accTextY) {
                        this.accTextY = svg.child(this.g, "text", { x: 365, y: 285, class: "sim-text" }) as SVGTextElement;
                        this.accTextY.textContent = "";
                    }
                    this.accTextY.textContent = `ay:${-y}`;
                }
                if (acc.flags & AccelerometerFlag.Z) {
                    if (!this.accTextZ) {
                        this.accTextZ = svg.child(this.g, "text", { x: 365, y: 310, class: "sim-text" }) as SVGTextElement;
                        this.accTextZ.textContent = "";
                    }
                    this.accTextZ.textContent = `az:${z}`;
                }
            }
        }