- function Finger(container) {
- var EMPTY = {};
- get('images/fingeri.svg', function(svg) {
- this.el = document.createElement('div');
- this.el.innerHTML = svg;
- this.left = false;
- this.joints = this.el.querySelectorAll('.joint');
- _.each(this.joints, function(j) {
- j.origin = j.getAttribute('data-origin');
- j.left = parseFloat(j.getAttribute('data-left'));
- j.right = parseFloat(j.getAttribute('data-right'));
- j.elastic = new Elastic();
- j.elastic.strength = parseFloat(j.getAttribute('data-strength'));
- j.elastic.damping = parseFloat(j.getAttribute('data-damping'));
- j.elastic.onChange = function(rotation) {
- j.setAttribute('transform', 'rotate(' + rotation + ' ' + j.origin + ')');
- };
- }, this);
- container.appendChild(this.el);
- _.each(this.joints, function(j, i) {
- j.elastic.dest = j.elastic.value = j.right;
- j.elastic.onChange(j.elastic.value);
- }, this);
- // this.waggle();
- // setInterval(_.bind(this.waggle, this), 1000);
- // midi.on({
- // type: 'noteOn',
- // channel: 10,
- // note: 36
- // }, function() {
- // this.waggle();
- // }, this);
- }, this);
- };
- Finger.prototype.setBPM = function(bpm) {
- this.bpm = bpm;
- };
- Finger.prototype.waggle = function() {
- if (!this.el) return;
- this.left = !this.left;
- _.each(this.joints, function(j, i) {
- j.elastic.dest = this.left ? j.left : j.right;
- // j.elastic.value = j.elastic.dest;
- }, this);
- };
- Finger.prototype.rest = function() {
- // _.each(this.joints, function(j) {
- // j.elastic.dest = 0;
- // });
- };
- Finger.prototype.update = function(millis) {
- var beat = Math.floor(this.millis2beat(millis + 200));
- if (beat != this.lastBeat) {
- this.waggle();
- }
- _.each(this.joints, Finger.updateJoint);
- this.lastBeat = beat;
- };
- Finger.updateJoint = function(j) {
- j.elastic.update();
- };
- Finger.prototype.millis2beat = function(millis) {
- return this.bpm/2/60000 * millis;
- }
Recent Pastes