How to use the framesync.timeSinceLastFrame function in framesync

To help you get started, we’ve selected a few framesync 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 Popmotion / popmotion / src / actions / spring.js View on Github external
update() {
    const { stiffness, damping, mass, from, to, restSpeed, restDisplacement } = this.props;
    const { delta, initialVelocity } = this;

    const timeDelta = timeSinceLastFrame() / 1000;
    const t = this.t = this.t + timeDelta;

    const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
    const angularFreq = Math.sqrt(stiffness / mass);
    const expoDecay = angularFreq * Math.sqrt(1.0 - (dampingRatio * dampingRatio));

    const x0 = 1;
    let oscillation = 0.0;

    // Underdamped
    if (dampingRatio < 1) {
      const envelope = Math.exp(-dampingRatio * angularFreq * t);
      oscillation = envelope * (((initialVelocity + dampingRatio * angularFreq * x0) / expoDecay) * Math.sin(expoDecay * t) + (x0 * Math.cos(expoDecay * t)));
      this.velocity = (envelope * ((Math.cos(expoDecay * t) * (initialVelocity + dampingRatio * angularFreq * x0)) - (expoDecay * x0 * Math.sin(expoDecay * t))) -
        ((dampingRatio * angularFreq * envelope) * ((((Math.sin(expoDecay * t) * (initialVelocity + dampingRatio * angularFreq * x0)) ) / expoDecay) + (x0 * Math.cos(expoDecay * t)))));
github Popmotion / popmotion / src / actions / physics.js View on Github external
update() {
    const { autoStopSpeed, acceleration, friction, velocity, spring, to } = this.props;
    let newVelocity = velocity;
    const elapsed = timeSinceLastFrame();

    // Apply acceleration to velocity
    if (acceleration) {
      newVelocity += speedPerFrame(acceleration, elapsed);
    }

    // Apply friction to velocity
    if (friction) {
      newVelocity *= (1 - friction) ** (elapsed / 100);
    }

    if (spring && to !== undefined) {
      const distanceToTarget = to - this.current;
      newVelocity += distanceToTarget * speedPerFrame(spring, elapsed);
    }
github Popmotion / popmotion / src / actions / rx.js View on Github external
const updateTween = () => {
    elapsed += timeSinceLastFrame();
    // const progress = clampProgress(getProgressFromValue(0, duration, elapsed));
    // const current = getValueFromProgress(from, to, ease(progress));
    update(elapsed);
  };
github Popmotion / popmotion / packages / popmotion / src / observers / animated-value.ts View on Github external
getVelocity: () => {
      const frame = currentFrameTime();
      const frameDelta = timeSinceLastFrame();
      return (frame - lastUpdateTimestamp <= frameDelta)
        ? speedPerSecond(current - prev, frameDelta)
        : 0;
    },
    update: (v: number) => {
github Popmotion / popmotion / src / actions / index.js View on Github external
scheduledUpdate = () => {
    this.lastUpdated = timeSinceLastFrame();
    this.prev = this.current;

    const { onUpdate, passive } = this.props;

    if (this.update) {
      this.current = this.update(this.current);
    }

    if (onUpdate) {
      onUpdate(this.get(), this);
    }

    this.fireListeners();

    if (!passive && this._isActive) {
      onFrameUpdate(this.scheduledUpdate);
github Popmotion / popmotion / src / _actions / inertia.js View on Github external
update() {
    const { autoStopDelta, timeConstant } = this.props;

    this.elapsed += timeSinceLastFrame();
    const delta = -this.amplitude * Math.exp(-this.elapsed / timeConstant);
    const isMoving = (delta > autoStopDelta || delta < -autoStopDelta);
    if (!isMoving) this.isComplete = true;
    return isMoving ? this.target + delta : this.target;
  }
github Popmotion / popmotion / src / actions / tween.js View on Github external
update() {
    const { duration, ease, from, to, playDirection } = this.props;

    if (!this.isManualUpdate) {
      this.elapsed += timeSinceLastFrame() * playDirection;
    }

    this.isManualUpdate = false;
    this.progress = clampProgress(getProgressFromValue(0, duration, this.elapsed));

    return getValueFromProgress(from, to, ease(this.progress));
  }
github Popmotion / popmotion / packages / popmotion / reactions / value.js View on Github external
ValueReaction.prototype.update = function (v) {
        _super.prototype.update.call(this, v);
        this.prev = this.current;
        this.current = v;
        this.timeDelta = framesync_1.timeSinceLastFrame();
    };
    ValueReaction.prototype.subscribe = function (observerCandidate) {
github Popmotion / popmotion / packages / popmotion / src / animations / tween / index.ts View on Github external
tweenTimer = onFrame().start((i) => {
      elapsed += timeSinceLastFrame() * playDirection;
      updateTween();
      if (isTweenComplete() && complete) {
        tweenTimer.stop();
        onFrameUpdate(complete, true);
      }
    });
  };