GitXplorerGitXplorer
P

Flailr

public
4 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
af0592d306b6529c045ff3733efbfb1f745b00c2

Do not fire a targetHit event on call to start.

PPaulCampbell committed 11 years ago
Unverified
1bbd74497c50bdbeeb78b33b0c2b216cc0a91c7f

tests tidied up

PPaulCampbell committed 11 years ago
Unverified
f7da722752170bc697177a24a3414a6ca5cb0ab5

added some tests

PPaulCampbell committed 11 years ago
Unverified
9349518d2714819c5a5717f981e317ec88644109

tidy up readme indetation etc

PPaulCampbell committed 11 years ago
Unverified
4b8c9c259cd3b14b8e0aacedb522b5ae6202e297

repo name change

PPaulCampbell committed 11 years ago
Unverified
62833b8fd39a74bc1c3fc418deb640798ba3791d

repo name change

PPaulCampbell committed 11 years ago

README

The README file for this repository.

Flailr js

Flail: verb

Wave or swing or cause to wave or swing wildly.

Motion detection from your webcam. In your browser.

Flailr js is a library for those of us who haven't got a Leap Motion, but want to interact with the browser by wildly waving their arms around.

See it in use here: http://flailr.jit.su

How does is work?

The basic premise is as follows:

  • We take a feed from the web cam using navigator.getUserMedia
  • We add a canvas to the page and stream the video onto it.
  • We add some hitTargets to the canvas (these are basically areas on the canvas that will shout if there has been significant movement over them.
  • We do some fancy blend mode difference business to check for movement in the camera and raise an event if there is enough movement over one of our hitTargets

Simple.

But how do you actually make it work?

So there are a few examples in the examples folder that are also running online at http://flailr.jit.su

Basically, include the script on your page:

<script src='/scripts/flailr.js'></script>

You can now instantiate a new flailr object:

var flailr = new Flailr();

Give values to a bunch of settings on your new flailr object:

Settings

containerId

flailr.containerId = 'container';

The id of a div you want the canvas adding to. Failing to specify will result in the canvas being added to directly to the body element.

showVideo

flailr.showVideo = true;

Sets whether you want the canvas element (and hence the web-cam stream) to be visible. Defaults to true.

showDifferenceCanvas

flailr.showDifferenceCanvas = false;

Show the difference canvas. Kind of shows what flailr is seeing wrt camera movement - can be helpful for debugging. Defaults for false.

width and height

flailr.width = 640
flailr.height = 480

Pixel width and height of the canvas with the video stream.

sensitivity

flailr.sensitivity = 100;

How sensitive the motion capture is... or: how much movement should flailr see over a hitTarget before raising an event. I seem to be able to get readings of up to about 250 movement_ by flailing WILDLY over a hit target.

hitTargets

flailr.hitTargets = [
        {x: 70, y: 350, width: 120, height: 120, graphic: '/images/snare.png'},
        {x: 400, y: 350, width: 120, height: 120, graphic: '/images/tom.png'}
      ];

This is an array of hitTargets. A hitTarget has an x and y position (position on the canvas), a width, a height and optionally a graphic (if you want the hitTarget to be visible. When there is movement over the hit target (above the required sensitivity level) a hit event will be raised.

addEventListener

  flailr.addEventListener('targetHit', function(e) {
    console.log('target-hit: ' + JSON.stringify(e))
  })

So, this is just to add functions to be called when certain events are raised. At the moment the only event that flailr will raise is a targetHit event

Now you just call start:

flailr.start()

All together now

<!DOCTYPE html>
<html>
<head>
  <title>Drums example</title>
  <script src='/scripts/flailr.js'></script>

</head>
<body>
  <div id='container'>

  </div>
</body>
<script>
  var flailr = new Flailr();
  flailr.containerId = 'container';
  flailr.hitTargets = [
        {id: 'snare', x: 70, y: 350, width: 120, height: 120, graphic: '/images/snare.png'},
        {id: 'tom', x: 400, y: 350, width: 120, height: 120, graphic: '/images/tom.png'}
      ];

  flailr.addEventListener('targetHit', function(e) {
    console.log('target-hit: ' + JSON.stringify(e))
  })

  flailr.start();

</script>
</html>

As noted - check the examples folder!

Todo

  • Improve API (it seems a bit messy to set up a new flailr atm)
  • Do we like the instantiating with the new keyword? Possibly replace this?
  • Check out browser support.
  • Get it to raise gesture events
    • SwipeRight
    • SwipeLeft
    • SwipeDown
    • SwipeUp