How to use nudged - 10 common examples

To help you get started, we’ve selected a few nudged examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taataa / tapspace / examples / play / app.js View on Github external
this.endTouchPoint = function (id) {
    // Debug
      if (!pointers.hasOwnProperty(id)) {
        console.error('Pointer ' + id + ' does not exist.')
      }

    // For each removed touch.
      commit()
      delete pointers[id]
      numPointers -= 1
      if (numPointers === 0) {
      // So numPointers was one.
      // So high-level gesture ends.
        this.emit('end', totalTransform)
      // Return transforms to identity.
        committedTransform = nudged.Transform.IDENTITY
        totalTransform = nudged.Transform.IDENTITY
      }
    }
  }
github taataa / tapspace / examples / play / src / Model.js View on Github external
// Debug
    if (!pointers.hasOwnProperty(id)) {
      console.error('Pointer ' + id + ' does not exist.')
    }

    // For each removed touch.
    commit()
    delete pointers[id]
    numPointers -= 1
    if (numPointers === 0) {
      // So numPointers was one.
      // So high-level gesture ends.
      this.emit('end', totalTransform)
      // Return transforms to identity.
      committedTransform = nudged.Transform.IDENTITY
      totalTransform = nudged.Transform.IDENTITY
    }
  }
}
github taataa / tapspace / examples / canvas / app.js View on Github external
// Debug
        if (!pointers.hasOwnProperty(id)) {
          console.error('Pointer ' + id + ' does not exist.')
        }

    // For each removed touch.
        commit()
        delete pointers[id]
        numPointers -= 1
        if (numPointers === 0) {
      // So numPointers was one.
      // So high-level gesture ends.
          this.emit('end', totalTransform)
      // Return transforms to identity.
          committedTransform = nudged.Transform.IDENTITY
          totalTransform = nudged.Transform.IDENTITY
        }
      }
    }
github taataa / tapspace / examples / play / app.js View on Github external
var Model = function () {
    Emitter(this)

  // For ongoing transformation, remember where the pointers started from
  // and keep track where they are now. We store this information to
  // the pointers variable. It has a property for each current pointer.
  //
  // Example:
  // {
  //   'pointerid': {dx: , dy: , rx: , ry}
  // }
    var pointers = {}
    var numPointers = 0

  // Cumulated transformation. Like a history.
    var committedTransform = nudged.Transform.IDENTITY
  // When the history is combined with the ongoing transformation,
  // the result is total transformation.
    var totalTransform = nudged.Transform.IDENTITY

  // Limit the frequency of fired events
  // TODO should be done outside of the Model.
    var previousMoveDateNow = Date.now()

    var commit = function () {
    // Move ongoint transformation to the committed transformation so that
    // the total transformation stays the same.

    // Commit ongoingTransformation. As a result
    // the domain and range of all pointers become equal.
      var id, p, domain, range, t
      domain = []
github taataa / tapspace / lib / SpacePoint.js View on Github external
proto.toSpace = function () {
  // Create a new SpacePoint at same location but represented on space coords.
  //
  // Implementation note:
  //   We already have coord. transf. from the current plane to the space:
  //     plane._T
  var xySpace = this._T.transform(this.xy)
  var spaceMock = { '_T': nudged.Transform.IDENTITY }
  return new SpacePoint(spaceMock, xySpace)
}
github taataa / tapspace / examples / canvas / app.js View on Github external
var Model = function () {
      Emitter(this)

  // For ongoing transformation, remember where the pointers started from
  // and keep track where they are now. We store this information to
  // the pointers variable. It has a property for each current pointer.
  //
  // Example:
  // {
  //   'pointerid': {dx: , dy: , rx: , ry}
  // }
      var pointers = {}
      var numPointers = 0

  // Cumulated transformation. Like a history.
      var committedTransform = nudged.Transform.IDENTITY
  // When the history is combined with the ongoing transformation,
  // the result is total transformation.
      var totalTransform = nudged.Transform.IDENTITY

  // Limit the frequency of fired events
  // TODO should be done outside of the Model.
      var previousMoveDateNow = Date.now()

      var commit = function () {
    // Move ongoint transformation to the committed transformation so that
    // the total transformation stays the same.

    // Commit ongoingTransformation. As a result
    // the domain and range of all pointers become equal.
        var id, p, domain, range, t
        domain = []
github taataa / tapspace / examples / play / src / Model.js View on Github external
var Model = function () {
  Emitter(this)

  // For ongoing transformation, remember where the pointers started from
  // and keep track where they are now. We store this information to
  // the pointers variable. It has a property for each current pointer.
  //
  // Example:
  // {
  //   'pointerid': {dx: , dy: , rx: , ry}
  // }
  var pointers = {}
  var numPointers = 0

  // Cumulated transformation. Like a history.
  var committedTransform = nudged.Transform.IDENTITY
  // When the history is combined with the ongoing transformation,
  // the result is total transformation.
  var totalTransform = nudged.Transform.IDENTITY

  // Limit the frequency of fired events
  // TODO should be done outside of the Model.
  var previousMoveDateNow = Date.now()

  var commit = function () {
    // Move ongoint transformation to the committed transformation so that
    // the total transformation stays the same.

    // Commit ongoingTransformation. As a result
    // the domain and range of all pointers become equal.
    var id, p, domain, range, t
    domain = []
github taataa / tapspace / src / Transform.js View on Github external
// API v3.0.0

var nudged = require('nudged');

module.exports = nudged.Transform;
github taataa / tapspace / lib / Touchable / Manager.js View on Github external
n = domain.length
    for (k in prevPointers) {
      if (prevPointers.hasOwnProperty(k) && nextPointers.hasOwnProperty(k)) {
        totalTravel += Math.abs(prevPointers[k][0] - nextPointers[k][0]) / n
        totalTravel += Math.abs(prevPointers[k][1] - nextPointers[k][1]) / n
      }
    }

    // Compute current position of the pivot on the plane.
    // Pivot will be undefined if mode has no pivot but enables translation.
    pivot = toRawPivot(self.mode, self.plane)
    // Get current nudged-compatible transformation type string
    type = utils.convertToTransformationType(mode)

    // Estimate optimal transformation
    tr = nudged.estimate(type, domain, range, pivot)

    // Apply the transformation to plane. We also
    // memorize the new pointers for the next onMove call.
    // We want to memorize only their relative location on the plane.
    // This way transformations of the view and parents between
    // onMove calls become part of the resulting transformation.
    // Note that transformBy emits 'transformed' that might eventually
    // cause transformations in the space. Therefore we should do all
    // coordinate-plane conversions before transformBy to avoid weird bugs.
    if (self.view === self.plane) {
      // Somehow we do not need the following line with views:
      // pointersOnItem = multiplyLeft(nextPointersOnItem, tr)
      // If we use the line, everything shakes.
      pointersOnItem = nextPointersOnItem
      // Shortcut for:
      //   itr = new tapspace.geom.ITransform(tr, plane)
github taataa / tapspace / lib / SpaceTransform.js View on Github external
var normPivot
  if (typeof pivot !== 'undefined') {
    normPivot = pivot.toPointOn(plane)
  }

  // Allow single points
  if (domain.hasOwnProperty('_T')) { domain = [domain] }
  if (range.hasOwnProperty('_T')) { range = [range] }

  // Convert all SpacePoints onto the plane and to arrays
  var normDomain = SpaceTransform.normalizeToPoints(domain, plane)
  var normRange = SpaceTransform.normalizeToPoints(range, plane)

  // Then compute optimal transformation on the plane
  var T = nudged.estimate(type, normDomain, normRange, normPivot)
  return new SpaceTransform(plane, T)
}

nudged

Affine transformation estimator e.g. for multi-touch gestures and calibration

MIT
Latest version published 1 month ago

Package Health Score

70 / 100
Full package analysis