Skip to content

Instantly share code, notes, and snippets.

@rowan-m
Created August 27, 2019 09:18
Show Gist options
  • Save rowan-m/af8604d705d6a15e6a7de7a40d946b55 to your computer and use it in GitHub Desktop.
Save rowan-m/af8604d705d6a15e6a7de7a40d946b55 to your computer and use it in GitHub Desktop.
// _onPointermove(e)
this._touchX = e.clientX;
this._touchY = e.clientY;
this._angle =
// initial rotation of the element
this._initialAngle
// subtract the starting touch angle
- this._initialTouchAngle
// add the current touch angle
+ Math.atan2(this._touchY - this._centerY, this._touchX - this._centerX);
// Normalise value back into a 2π range
this._angle = (this._angle + TWO_PI) % TWO_PI;
// Done, update the value!
this.value = this._angle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment