Git Product home page Git Product logo

silly-app-demo's Introduction

Motion Sensor and Web App demo

0) Fork and clone, or download this repo

Cloning

cd to/your/destination/folder
git clone https://github.com/potatowagon/silly-app-demo.git 

Add remote

git remote add origin https://github.com/<your-github-username>/silly-app-demo.git

copy your link from github's green clone button

1) Adjust Chrome flags

Android Chrome disables motion sensors and audio play from custom event triggers by default (Since chrome version 63). Enable them for your app to work.

In Chrome search bar go to

about:flags

Search for Generic Sensor and change to Enabled.
Search for Autoplay policy and change to No user gesture is required.

2) Code Snippets

HTML Button

Let's add a button!
Paste this code under /*INSERT HTML BUTTON HERE*/ in index.html

<button type="button" onclick="scream()">Tickle!</button>

Make Button scream

Clicking on the button, scream() function is called. Lets define it.

Paste this under /* INSERT SCREAM FOR BUTTON CLICK FUNCTION HERE*/ in index.js

function scream() {
    var scream = new Audio(randomPicker(app.audio));
    scream.play();
}

Linear Acceleration Sensor

This is your accelerometer. This detects linear acceration without counting in gravity.

Paste this code snippet under /*INSERT ACCELEROMETER HERE*/ in index.js

try {
    let sensor = new LinearAccelerationSensor({ frequency: 60 });
    sensor.start();

    sensor.onreading = () => {
        var event = new CustomEvent('devicemotion', {
            detail: {
                acceleration: {
                    x: sensor.x,
                    y: sensor.y,
                    z: sensor.z
                }
            }
        });
        window.dispatchEvent(event);
    }
    sensor.onerror = event => console.log(event.error.name, event.error.message);
}
catch (e) {
    console.log(e);
    app.usingGenericSensor = false;
}

More info on motion sensors

ADD AN EVENT LISTENER TO WINDOW

So window (your open chrome window) will catch the devicemotion Event thrown by sensor.

Paste this under /*ADD AN EVENT LISTENER TO WINDOW*/ in index.js

window.addEventListener('devicemotion', deviceMotionHandler, false);

Make app scream

Paste this code snippet under /*DO SILLY STUFF*/ in index.js

var scream = new Audio(randomPicker(app.audio));
scream.play();
sleep(2000);

3) Stage, Commit, Push

ONLY FOR GIT USERS

Stage

git add --all

Commit

git commit -m "your message"

Push your local changes to Github

git push origin master:master

4) Deploy to Azure

Dashboard > your-app > deployment options

Configure either dropbox or Github

alt text alt text

How to dropbox

silly

silly

silly-app-demo's People

Contributors

sharan8 avatar pantalaimon1988 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.