From adc27cc80ef0cd1200a528d6fdcf121d76bb3e54 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 28 Feb 2017 12:29:25 -0800 Subject: [PATCH] better 3d effect --- sim/visuals/microbit.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sim/visuals/microbit.ts b/sim/visuals/microbit.ts index 6db5835c..781bf0cd 100644 --- a/sim/visuals/microbit.ts +++ b/sim/visuals/microbit.ts @@ -1386,11 +1386,13 @@ namespace pxsim.visuals { let state = this.board; if (!state || !state.accelerometerState.accelerometer.isActive) return; - let x = state.accelerometerState.accelerometer.getX(); - let y = -state.accelerometerState.accelerometer.getY(); - let af = 8 / 1023; + const x = state.accelerometerState.accelerometer.getX(); + const y = -state.accelerometerState.accelerometer.getY(); + const af = 8 / 1023; + const s = 1 - Math.min(0.1, Math.pow(Math.max(Math.abs(x), Math.abs(y)) / 1023, 2) / 35); - this.element.style.transform = "perspective(30em) rotateX(" + y * af + "deg) rotateY(" + x * af + "deg)" + this.element.style.transform = `perspective(30em) rotateX(${y * af}deg) rotateY(${x * af}deg) scale(${s}, ${s})` + this.element.style.perspectiveOrigin = "50% 50% 50%"; this.element.style.perspective = "30em"; }