Developer Remy Sharp has unveiled Remote-Tilt, a polyfill that enables you to send motion events to a web page. The script works in Chrome, Safari and Opera, and can be added through a single line of JavaScript.
Sharp told us that he built Remote-Tilt for the usual reasons he builds anything: "I was stuck trying to do something, and so I created a tool to do that thing. I was planning on adding motion events to a website I had worked on, and although I know how they work, the values in the events don't really mean much to me."
The usual process for working on such functionality, explained Sharp, is a "horrible loop" of writing code, pointing a mobile device at it, and testing; furthermore, debugging on mobile devices is fiddly. "But I figured these are just events and I could simulate the values using a simple JavaScript polyfill," he told us. "Once I had the initial pop-up working, I quickly realised I could open my simulator on a mobile device that had a gyroscope or accelerometer and just pipe those events from my phone to my development project."
Development itself was, according to Sharp, a challenge, in the sense of making the whole thing a single script include – "That's a single script to create the pop-up. A single script that actually is the pop-up. A single script with the images, events, everything." – And he ran into problems in Chrome, but considers his script an edge case. "But piping events from the mobile phone to the desktop is pretty straightforward and very similar to the technique I use to create a remote control for mobiles. And, all the code was written in a matter of a couple of days – it's still just a single script with a simple server after all!"